SlideShare a Scribd company logo
1 of 65
PHP 5 memory
Understand and master
Hello everybody
 Julien PAULI
 Programming with PHP since early 2000s
 Programming in C
 PHP Internals programmer/reviewer
 PHP 5.5 & 5.6 Release Manager
 @julienpauli
 Tech blog at jpauli.github.io
 jpauli@php.net
What about you ?
 Got some Unix/Linux understandings ?
 Have already experienced C programming ?
 Have already experienced PHP programming ?
What we'll cover together
 Memory , what's that ?
 bytes, stack, heap, etc.
 Measuring a process memory consumption
 memory image map analysis
 Understanding PHP memory consumption
 Zend Memory Manager coming
 Measuring PHP memory consumption
 from PHP land or from system land
Memory from hardware
Memory from software
Memory in a user process
 The Virtual Memory image is divided in segments
 text
 data
 heap
 stack
Memory usage can grow
 Stack will grow as functions will get called
 And will narrow as the calls stop and return
 Heap will grow as the programmer will decide
 Using dynamic allocation functions (malloc, mmap)
 Programmer has to free memory by hand
 If not : memory leak
Monitoring memory
Linux memory monitoring
 'top' or /proc FS
> cat /proc/28754/status
VmPeak: 20452 kB
VmSize: 20324 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 316 kB
VmRSS: 316 kB
VmData: 16440 kB
VmStk: 136 kB
VmExe: 4 kB
VmLib: 1664 kB
VmPTE: 28 kB
VmSwap: 0 kB
Size of the VM map (out of total mem)
Resident Set Size : Size actually in PM
Size of the data segment in VM
Size of the stack segment in VM
Size of the text segment in VM
pid
Going even deeper
 Let's show the detailed process memory map :
> cat /proc/28754/smaps
shared segment
private mem
shared mem
PHP !
PHP, just a process
 PHP is just a process like any other
 You then can monitor its memory usage by asking
the OS
<?php
passthru(sprintf('cat /proc/%d/status', getmypid()));
<?php
function heap() {
return shell_exec(sprintf('grep "VmRSS:" /proc/%d/status', getmypid()));
}
The PHP model
Startup
Shutdown
Request #1
Request #2
Request #3
Startup
Shutdown
Request #1
Request #2
Request #3
php-fpm worker#1 php-fpm worker#2
The PHP model
 One same process may treat many requests
 If the process leaks memory, you'll suffer from that
 Request n+1 must know nothing about request n
 Need to "flush" the request-allocated memory
 Need to track request-bound memory claims
 ZendMM is the layer that does the job
 Share-nothing architecture : by design.
Inside PHP
 PHP internal request-bound heap allocator :
Zend Memory Manager
Why a custom layer ?
 ZendMM
 Allows monitoring of request-bound heap usage by
basically counting malloc/free calls
 Allows the PHP user to limit the heap mem usage
 Allows caching of alloced blocks to prevent memory
fragmentation and syscalls
 Allows preallocating blocks of well-known-sizes for
PHP internal structures to fit-in in an aligned way
 Ease memory leaks debugging in core and exts
ZendMM guards and leak tracker
 Only works in debug mode PHP
 report_memleaks=1 in php.ini
 Does NOT replace valgrind
Zend MM test script
<?php
ini_set('memory_limit', -1); /* unlimited ZendMM heap */
function heap() {
return shell_exec(sprintf('grep "VmRSS:" /proc/%d/status', getmypid()));
}
echo heap();
$a = range(1, 1024*1024); /* Stress memory by allocating */
echo heap();
unset($a); /* Stress memory by freeing */
echo heap();
Zend MM launch test
> time USE_ZEND_ALLOC=1 php zendmm.php
VmRSS: 9640 kB
VmRSS: 159296 kB
VmRSS: 10068 kB
real 0m0.237s
user 0m0.148s
sys 0m0.080s
> time USE_ZEND_ALLOC=0 php zendmm.php
VmRSS: 9608 kB
VmRSS: 148988 kB
VmRSS: 140804 kB
real 0m0.288s
user 0m0.176s
sys 0m0.108s
Valgrind tests for Symfony2 command
 app/console runs lots of PHP code under SF2
>USE_ZEND_ALLOC=1 valgrind php app/console debug:container
total heap usage: 84,000 allocs, 84,000 frees, 25,966,154 bytes allocated
>USE_ZEND_ALLOC=0 valgrind php app/console debug:container
total heap usage: 813,570 allocs, 813,570 frees, 74,579,732 bytes allocated
ZendMM internals
ZendMM benefits
 Better memory management
 More memory efficient
 Far less malloc/free calls
 Less context switches, less Kernel stress
 Less CPU usage
 Less heap fragmentation / compaction
 A PHP ~10% faster with ZendMM enabled
 Really depends on use-case
Memory manager internals
 Layer on top of the heap
 Will allocate memory from the heap by chunks of
customizable size (segments)
 Will use a customizable low level heap (malloc /
mmap)
A quick word on ZendMM internals
 ZEND_MM_SEG_SIZE env variable to customize
segment size
 Must be power-of-two aligned
 Default value is 256Kb
ZendMM in PHP user land
 memory_limit (INI setting)
 memory_get_usage(true)
 Returns the size of all the allocated segments
 memory_get_usage()
 Returns the occupied size in all the allocated
segments
 memory_get_[peak]_usage([real])
 Returns the max memory that has been
allocated/used. Could have been freed meantime
ZendMM memory monitoring
ini_set('memory_limit', -1); // unlimited memory
function get_mem_stats() {
printf("Memory usage %.2f Kbn", memory_get_usage() / 1024);
if ($segSize = getenv('ZEND_MM_SEG_SIZE')) {
printf("Heap segmentation : %d segments of %d bytes (%d Kb used)n",
memory_get_usage(1)/$segSize, $segSize, memory_get_usage(1)/1024);
}
}
get_mem_stats();
$a = str_repeat('a', 1024*1024*10); // 10 Mb
get_mem_stats();
Adjusting heap segment size
Adjusting heap segment size
 Segment size = 256Kb (default value)
 Segment size = 4Mb
$> ZEND_MM_SEG_SIZE=262144 php /tmp/mem.php
Memory usage 221.26 Kb
Heap segmentation : 1 segments of 262144 bytes (256 Kb used)
Memory usage 10461.47 Kb
Heap segmentation : 42 segments of 262144 bytes (10752 Kb used)
get_mem_stats();
$a = str_repeat('a', 1024*1024*10); // 10 Mb
get_mem_stats();
$> ZEND_MM_SEG_SIZE=4194304 php /tmp/mem.php
Memory usage 221.26 Kb
Heap segmentation : 1 segments of 4194304 bytes (4096 Kb used)
Memory usage 10461.47 Kb
Heap segmentation : 4 segments of 4194304 bytes (16384 Kb used)
memory_get_usage() ?
 memory_get_usage() tells you how much your
allocated blocs consume
 They usually don't fill their segment entirely
 Thus memory_get_usage(true) shows more
 This doesn't count stack
 This does only count request-bound memory
 This doesn't count linked libraries present in the
process memory map
 This doesn't show non-request-bound memory
Real memory image
 valgrind massif
Massif memory monitoring
--------------------------------------------------------------------------------
n time(ms) total(B) useful-heap(B) extra-heap(B) stacks(B)
--------------------------------------------------------------------------------
0 0 0 0 0 0
1 309 56 37 19 0
2 341 384 357 27 0
3 376 1,343,992 1,340,371 3,621 0
4 408 1,360,480 1,355,289 5,191 0
5 443 1,376,512 1,367,265 9,247 0
6 471 1,753,976 1,735,671 18,305 0
7 505 2,345,152 2,275,927 69,225 0
8 535 2,405,224 2,329,798 75,426 0
9 570 2,433,408 2,348,849 84,559 0
10 613 2,592,912 2,461,650 131,262 0
11 657 2,681,240 2,534,247 146,993 0
Massif details
94.52% (2,534,247B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->39.11% (1,048,576B) 0x87A7BB: zend_interned_strings_init (zend_string.c:48)
|
->17.70% (474,464B) 0x866449: _zend_hash_quick_add_or_update (zend_alloc.h:95)
| ->16.48% (441,936B) 0x85F66D: zend_register_functions (zend_API.c:2138)
|
->11.93% (320,000B) 0x878625: gc_init (zend_gc.c:124)
| ->11.93% (320,000B) 0x8585DF: OnUpdateGCEnabled (zend.c:82)
| ->11.93% (320,000B) 0x86E353: zend_register_ini_entries (zend_ini.c:208)
Recommendations / statements
 Understand memory_get_usage()
 It only shows request-bound allocations, not
persistent allocations (that reside through requests)
 PHP extensions may allocate persistent memory
 Do NOT activate extensions you will not use
 Libraries used by PHP may also allocate persistent
memory
 Use your OS to monitor your process memory
accurately
Playing with memory in PHP user land
Master your PHP mem usage
 In PHP land ...
 all variable types consume memory
 every script asked for compilation will eat memory
 This memory will be allocated using ZendMM
 The memory for parsed script is freed when the
request ends
 The memory for user variable is freed when the
data is not used any more
 And here comes the challenge
 When isn't the data needed any more ??
Compilation eats memory
 Compiling a script eats request-bound memory
 If you compile a class, that eats lots of memory
 You'd better use that class at runtime
 Use an autoloader to be sure
<?php
$mem = memory_get_usage();
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../src/Symfony/Component/DependencyInjection/ContainerBuilder.php'
echo memory_get_usage() - $mem . "n";
php app/bar.php
246,692
PHP Variables
 Variables are internally zval structs
PHP Variables
 What eats memory is what is stored into the zval,
not really the zval itself :
 A huge string
 Tip : a file_get_contents('huge-file') is a huge string
 A complex array or object
 Resources don't really consume mem in zval
<?php
/* This consumes sizeof(zval) + 1024 bytes */
$a = str_repeat('a', 1024);
PHP Variables
 What you want to avoid is have PHP duplicate the
zval
 But PHP is kind about that
 What you want to happen in PHP freeing the
memory ASAP
 Should you know when PHP duplicates or frees zval
, that's the most important !
zvals and refcount
 PHP simply counts how many symbols (PHP
vars) point to a zval
 This is called the refcount
<?php
$a = "foo";
$b = $a;
zvals and refcount
 PHP uses a CopyOnWrite (COW) system for
zvals
 Memory is saved
 Memory gets allocated only on changes
<?php
$a = "foo";
$b = $a;
$a = 17;
zvals and refcount
 PHP frees memory for a zval
when its refcount reaches 0
 Yes, unset() just refcount-- ,
that's all
<?php
$a = "foo";
$b = $a;
$c = $b;
$b = "bar";
unset($a);
No references needed
 You see how smart PHP is with memory ?
 It's been designed with that in mind
 No references needed to hint PHP !
 Don't try to hint PHP with references
 References can lead to adverse effects
 Force PHP to copy a zval
 Prevents PHP from freeing memory of a zval
&
Tracking refcount
 xdebug_debug_zval()
 symfony_zval_info()
namespace Foo;
class A
{
public $var = 'varA';
}
$a = new A();
xdebug_debug_zval('a');
a: (refcount=1, is_ref=0)=class FooA { public $var =
(refcount=2, is_ref=0)='varA'; }
Tracking refcount
namespace Foo;
class C
{
public $b;
public function __construct(B $b) {
$this->b = $b;
}
}
$c = new C($b = new B);
xdebug_debug_zval('c');
c: (refcount=1, is_ref=0)=class FooC { public $b = (refcount=2, is_ref=0)=class FooB { } }
namespace Foo;
class B
{
}
unset($b);
xdebug_debug_zval('c');
c: (refcount=1, is_ref=0)=class FooC { }
c: (refcount=1, is_ref=0)=class FooC { public $b = (refcount=1, is_ref=0)=class FooB { } }
unset($c->b);
xdebug_debug_zval('c');
Garbage collector ?
 As of PHP5.3 , a garbage collector exists
 Used to free circular references
 And that's all !
 PHP already frees itself your vars as their
refcount reaches 0
 And it's always been like that
Circular references
$a = new A;
$b = new B
(object) 'A'
refcount = 1
$a (object) 'B'
refcount = 1
$b
Circular references
$a->b = $b;
$b->a = $a;
(object) 'A'
refcount = 2
$a (object) 'B'
refcount = 2
$b
$b->a $a->b
Circular references
 Objects are still in memory but no more PHP var
point to them
 We can call that a "PHP Userland memory leak"
unset($a, $b);
(object) 'A'
refcount = 1
$b->a (object) 'B'
refcount = 1
$a->b
Garbage collector
$a = new A;
$b = new B;
$a->b = $b;
$b->a = $a;
unset($a, $b);
echo gc_collect_cycles(); // 2
PHP references
PHP references main line
 Using references (&) in PHP can really fool you
 They usually force the engine to duplicate memory
containers
 Which is bad for performance
 Especially when the var container is huge
References mismatch
<?php
function foo($data)
{
echo "in function : " . memory_get_usage() . "n";
}
echo "Initial memory : " . memory_get_usage() . "n";
$r = range(1, 1024);
echo "Array created : " . memory_get_usage() . "n";
foo($r);
echo "End of function " . memory_get_usage() . "n";
Initial memory : 227.136
Array created : 374.912
in function : 374.944
End of function 374.944
References mismatch
<?php
function foo($data)
{
echo "in function : " . memory_get_usage() . "n";
}
echo "Initial memory : " . memory_get_usage() . "n";
$r = range(1, 1024);
$r2 = &$r;
echo "Array created : " . memory_get_usage() . "n";
foo($r);
echo "End of function " . memory_get_usage() . "n";
Initial memory : 227.208
Array created : 375.096
in function : 473.584
End of function 375.128
When does the engine separate ?
 In any mismatch case :
zval passed to function arginfo decl. zval received in function separated by engine?
is_ref=0
refcount = 1
pass_by_ref=0 is_ref=0
refcount = 2
NO
is_ref=1
refcount > 1
pass_by_ref=0 is_ref=1
refcount =1
YES
is_ref=0
refcount > 1
pass_by_ref=0 is_ref=0
refcount > 1 ++
NO
is_ref=0
refcount = 1
pass_by_ref=1 is_ref=1
refcount = 2
YES
is_ref=1
refcount > 1
pass_by_ref=1 is_ref=1
refcount > 1 ++
NO
is_ref=0
refcount > 1
pass_by_ref=1 is_ref=1
refcount = 2
YES
Symfony_debug to notice mismatches
 https://github.com/symfony/debug
function bar($var) { }
$a = "foo";
$b = &$a;
bar($a);
Notice: Separating zval for call to function 'bar' in /tmp/memory.php on line 20
foreach behavior
Foreach separation behavior
 It happens sometimes foreach() duplicates your
variable for iteration
 This will eat performances in case of big or
complex arrays being iterated
 There is nothing special to say about objects
implementing Traversable
 The behavior is then just yours
foreach iterating array #1
 If the variable has a refcount of 1, no duplication is
performed by foreach()
$a = range(1,1024);
echo memory_get_usage() . "n" ;
foreach ($a as $v) {
if ($v == 1) {
echo memory_get_usage() . "n" ;
}
}
echo memory_get_usage() . "n" ;
373936
374056
374056
foreach iterating array #2
 If the variable has a refcount >1, foreach() will
duplicate it fully for iteration
$a = range(1,1024);
$b = $a;
echo memory_get_usage() . "n" ;
foreach ($a as $v) {
if ($v == 1) {
echo memory_get_usage() . "n" ;
}
}
echo memory_get_usage() . "n" ;
373936
472512
374056
foreach iterating array #3
 If the variable is a reference, foreach() will work
onto that array and won't perform duplication
$a = range(1,1024);
$b = &$a;
echo memory_get_usage() . "n" ;
foreach ($a as $v) {
if ($v == 1) {
echo memory_get_usage() . "n" ;
}
}
echo memory_get_usage() . "n" ;
373936
374056
374056
Monitoring memory usage
 Not much tools exist (for PHP)
 memory_get_usage()
 OS' help (/proc , pmap , etc...)
 Valgrind with massif tool
 PHP Extensions
 Xdebug
 memprof
 memtrack
Quick intro to memprof
 https://github.com/arnaud-lb/php-memory-profiler
$b = range(1, 1024 * 1024); /* a lot of memory */
$b[] = foo();
loader('/Zend/Date.php'); /* a lot of PHP source code */
memprof_dump_callgrind(fopen('/tmp/trace.out', 'w'));
Thank you for listening

More Related Content

What's hot

Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?Samsung Open Source Group
 
Memory Compaction in Linux Kernel.pdf
Memory Compaction in Linux Kernel.pdfMemory Compaction in Linux Kernel.pdf
Memory Compaction in Linux Kernel.pdfAdrian Huang
 
Hacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sitesHacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sitesMikhail Egorov
 
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programsAEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programsMikhail Egorov
 
UseNUMA做了什么?(2012-03-14)
UseNUMA做了什么?(2012-03-14)UseNUMA做了什么?(2012-03-14)
UseNUMA做了什么?(2012-03-14)Kris Mok
 
Percona xtrabackup - MySQL Meetup @ Mumbai
Percona xtrabackup - MySQL Meetup @ MumbaiPercona xtrabackup - MySQL Meetup @ Mumbai
Percona xtrabackup - MySQL Meetup @ MumbaiNilnandan Joshi
 
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...Adrian Huang
 
BlueStore: a new, faster storage backend for Ceph
BlueStore: a new, faster storage backend for CephBlueStore: a new, faster storage backend for Ceph
BlueStore: a new, faster storage backend for CephSage Weil
 
Physical Memory Management.pdf
Physical Memory Management.pdfPhysical Memory Management.pdf
Physical Memory Management.pdfAdrian Huang
 
Reverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux KernelReverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux KernelAdrian Huang
 
Rules to Hack By - Offensivecon 2022 keynote
Rules to Hack By - Offensivecon 2022 keynoteRules to Hack By - Offensivecon 2022 keynote
Rules to Hack By - Offensivecon 2022 keynoteMarkDowd13
 
Hunting for security bugs in AEM webapps
Hunting for security bugs in AEM webappsHunting for security bugs in AEM webapps
Hunting for security bugs in AEM webappsMikhail Egorov
 
Linux kernel tracing
Linux kernel tracingLinux kernel tracing
Linux kernel tracingViller Hsiao
 
HBase Read High Availability Using Timeline Consistent Region Replicas
HBase  Read High Availability Using Timeline Consistent Region ReplicasHBase  Read High Availability Using Timeline Consistent Region Replicas
HBase Read High Availability Using Timeline Consistent Region Replicasenissoz
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernelAdrian Huang
 
Lock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesLock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesRoman Elizarov
 
Content Security Policy
Content Security PolicyContent Security Policy
Content Security PolicyAustin Gil
 
【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制
【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制
【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制裝機安 Angelo
 

What's hot (20)

Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?Reconnaissance of Virtio: What’s new and how it’s all connected?
Reconnaissance of Virtio: What’s new and how it’s all connected?
 
Memory Compaction in Linux Kernel.pdf
Memory Compaction in Linux Kernel.pdfMemory Compaction in Linux Kernel.pdf
Memory Compaction in Linux Kernel.pdf
 
Hacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sitesHacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sites
 
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programsAEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
AEM hacker - approaching Adobe Experience Manager webapps in bug bounty programs
 
Rust Intro
Rust IntroRust Intro
Rust Intro
 
UseNUMA做了什么?(2012-03-14)
UseNUMA做了什么?(2012-03-14)UseNUMA做了什么?(2012-03-14)
UseNUMA做了什么?(2012-03-14)
 
Percona xtrabackup - MySQL Meetup @ Mumbai
Percona xtrabackup - MySQL Meetup @ MumbaiPercona xtrabackup - MySQL Meetup @ Mumbai
Percona xtrabackup - MySQL Meetup @ Mumbai
 
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
 
BlueStore: a new, faster storage backend for Ceph
BlueStore: a new, faster storage backend for CephBlueStore: a new, faster storage backend for Ceph
BlueStore: a new, faster storage backend for Ceph
 
Physical Memory Management.pdf
Physical Memory Management.pdfPhysical Memory Management.pdf
Physical Memory Management.pdf
 
Reverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux KernelReverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux Kernel
 
Rules to Hack By - Offensivecon 2022 keynote
Rules to Hack By - Offensivecon 2022 keynoteRules to Hack By - Offensivecon 2022 keynote
Rules to Hack By - Offensivecon 2022 keynote
 
Hunting for security bugs in AEM webapps
Hunting for security bugs in AEM webappsHunting for security bugs in AEM webapps
Hunting for security bugs in AEM webapps
 
Linux kernel tracing
Linux kernel tracingLinux kernel tracing
Linux kernel tracing
 
Ceph issue 해결 사례
Ceph issue 해결 사례Ceph issue 해결 사례
Ceph issue 해결 사례
 
HBase Read High Availability Using Timeline Consistent Region Replicas
HBase  Read High Availability Using Timeline Consistent Region ReplicasHBase  Read High Availability Using Timeline Consistent Region Replicas
HBase Read High Availability Using Timeline Consistent Region Replicas
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernel
 
Lock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin CoroutinesLock-free algorithms for Kotlin Coroutines
Lock-free algorithms for Kotlin Coroutines
 
Content Security Policy
Content Security PolicyContent Security Policy
Content Security Policy
 
【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制
【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制
【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制
 

Viewers also liked

How PHP Works ?
How PHP Works ?How PHP Works ?
How PHP Works ?Ravi Raj
 
The Php Life Cycle
The Php Life CycleThe Php Life Cycle
The Php Life CycleXinchen Hui
 
PHP, Under The Hood - DPC
PHP, Under The Hood - DPCPHP, Under The Hood - DPC
PHP, Under The Hood - DPCAnthony Ferrara
 
گزارشی از برنامه‌نویسی موازی در پی‌اچ‌پی
گزارشی از برنامه‌نویسی موازی در پی‌اچ‌پیگزارشی از برنامه‌نویسی موازی در پی‌اچ‌پی
گزارشی از برنامه‌نویسی موازی در پی‌اچ‌پیAla Alam Falaki
 
Php On Windows Internals
Php On Windows InternalsPhp On Windows Internals
Php On Windows InternalsPierre Joye
 
Extending php (7), the basics
Extending php (7), the basicsExtending php (7), the basics
Extending php (7), the basicsPierre Joye
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objectsjulien pauli
 
استفاده از شبکه عصبی مصنوعی در پی‌اچ‌پی
استفاده از شبکه عصبی مصنوعی در پی‌اچ‌پیاستفاده از شبکه عصبی مصنوعی در پی‌اچ‌پی
استفاده از شبکه عصبی مصنوعی در پی‌اچ‌پیAla Alam Falaki
 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshopjulien pauli
 
Phpcompilerinternals 090824022750-phpapp02
Phpcompilerinternals 090824022750-phpapp02Phpcompilerinternals 090824022750-phpapp02
Phpcompilerinternals 090824022750-phpapp02philipo
 
Php 7.x 8.0 and hhvm and
Php 7.x 8.0 and hhvm and Php 7.x 8.0 and hhvm and
Php 7.x 8.0 and hhvm and Pierre Joye
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionjulien pauli
 
今日からはじめるディープラーニング
今日からはじめるディープラーニング今日からはじめるディープラーニング
今日からはじめるディープラーニングShingo Kitayama
 
Monitoring with sensu
Monitoring with sensuMonitoring with sensu
Monitoring with sensumiquelruizm
 

Viewers also liked (20)

How PHP Works ?
How PHP Works ?How PHP Works ?
How PHP Works ?
 
How PHP works
How PHP works How PHP works
How PHP works
 
The Php Life Cycle
The Php Life CycleThe Php Life Cycle
The Php Life Cycle
 
PHP, Under The Hood - DPC
PHP, Under The Hood - DPCPHP, Under The Hood - DPC
PHP, Under The Hood - DPC
 
PHP 7 new engine
PHP 7 new enginePHP 7 new engine
PHP 7 new engine
 
گزارشی از برنامه‌نویسی موازی در پی‌اچ‌پی
گزارشی از برنامه‌نویسی موازی در پی‌اچ‌پیگزارشی از برنامه‌نویسی موازی در پی‌اچ‌پی
گزارشی از برنامه‌نویسی موازی در پی‌اچ‌پی
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Linux memory
Linux memoryLinux memory
Linux memory
 
Php On Windows Internals
Php On Windows InternalsPhp On Windows Internals
Php On Windows Internals
 
Extending php (7), the basics
Extending php (7), the basicsExtending php (7), the basics
Extending php (7), the basics
 
Understanding PHP objects
Understanding PHP objectsUnderstanding PHP objects
Understanding PHP objects
 
استفاده از شبکه عصبی مصنوعی در پی‌اچ‌پی
استفاده از شبکه عصبی مصنوعی در پی‌اچ‌پیاستفاده از شبکه عصبی مصنوعی در پی‌اچ‌پی
استفاده از شبکه عصبی مصنوعی در پی‌اچ‌پی
 
Memory Management in WordPress
Memory Management in WordPressMemory Management in WordPress
Memory Management in WordPress
 
Php extensions workshop
Php extensions workshopPhp extensions workshop
Php extensions workshop
 
Phpcompilerinternals 090824022750-phpapp02
Phpcompilerinternals 090824022750-phpapp02Phpcompilerinternals 090824022750-phpapp02
Phpcompilerinternals 090824022750-phpapp02
 
Php 7.x 8.0 and hhvm and
Php 7.x 8.0 and hhvm and Php 7.x 8.0 and hhvm and
Php 7.x 8.0 and hhvm and
 
Mysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extensionMysqlnd, an unknown powerful PHP extension
Mysqlnd, an unknown powerful PHP extension
 
今日からはじめるディープラーニング
今日からはじめるディープラーニング今日からはじめるディープラーニング
今日からはじめるディープラーニング
 
MySQL under the siege
MySQL under the siegeMySQL under the siege
MySQL under the siege
 
Monitoring with sensu
Monitoring with sensuMonitoring with sensu
Monitoring with sensu
 

Similar to Understanding PHP memory

PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance毅 吕
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshopjulien pauli
 
php & performance
 php & performance php & performance
php & performancesimon8410
 
Linux memory consumption
Linux memory consumptionLinux memory consumption
Linux memory consumptionhaish
 
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusionAdvanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusionColdFusionConference
 
Developing High Performance and Scalable ColdFusion Application Using Terraco...
Developing High Performance and Scalable ColdFusion Application Using Terraco...Developing High Performance and Scalable ColdFusion Application Using Terraco...
Developing High Performance and Scalable ColdFusion Application Using Terraco...ColdFusionConference
 
Developing High Performance and Scalable ColdFusion Applications Using Terrac...
Developing High Performance and Scalable ColdFusion Applications Using Terrac...Developing High Performance and Scalable ColdFusion Applications Using Terrac...
Developing High Performance and Scalable ColdFusion Applications Using Terrac...Shailendra Prasad
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magentoMathew Beane
 
PHP Sessions and Non-Sessions
PHP Sessions and Non-SessionsPHP Sessions and Non-Sessions
PHP Sessions and Non-SessionsSven Rautenberg
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsMarcelo Pinheiro
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Wim Godden
 
performance optimization: Memory
performance optimization: Memoryperformance optimization: Memory
performance optimization: Memory晓东 杜
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsUlf Wendel
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalabilityWim Godden
 
ECECS 472572 Final Exam ProjectRemember to check the errata
ECECS 472572 Final Exam ProjectRemember to check the errata ECECS 472572 Final Exam ProjectRemember to check the errata
ECECS 472572 Final Exam ProjectRemember to check the errata EvonCanales257
 
ECECS 472572 Final Exam ProjectRemember to check the errat.docx
ECECS 472572 Final Exam ProjectRemember to check the errat.docxECECS 472572 Final Exam ProjectRemember to check the errat.docx
ECECS 472572 Final Exam ProjectRemember to check the errat.docxtidwellveronique
 
ECECS 472572 Final Exam ProjectRemember to check the err.docx
ECECS 472572 Final Exam ProjectRemember to check the err.docxECECS 472572 Final Exam ProjectRemember to check the err.docx
ECECS 472572 Final Exam ProjectRemember to check the err.docxtidwellveronique
 
PHP 7 OPCache extension review
PHP 7 OPCache extension reviewPHP 7 OPCache extension review
PHP 7 OPCache extension reviewjulien pauli
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APCBen Ramsey
 

Similar to Understanding PHP memory (20)

PHP & Performance
PHP & PerformancePHP & Performance
PHP & Performance
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshop
 
php & performance
 php & performance php & performance
php & performance
 
Linux memory consumption
Linux memory consumptionLinux memory consumption
Linux memory consumption
 
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusionAdvanced caching techniques with ehcache, big memory, terracotta, and coldfusion
Advanced caching techniques with ehcache, big memory, terracotta, and coldfusion
 
Developing High Performance and Scalable ColdFusion Application Using Terraco...
Developing High Performance and Scalable ColdFusion Application Using Terraco...Developing High Performance and Scalable ColdFusion Application Using Terraco...
Developing High Performance and Scalable ColdFusion Application Using Terraco...
 
Developing High Performance and Scalable ColdFusion Applications Using Terrac...
Developing High Performance and Scalable ColdFusion Applications Using Terrac...Developing High Performance and Scalable ColdFusion Applications Using Terrac...
Developing High Performance and Scalable ColdFusion Applications Using Terrac...
 
Zendcon scaling magento
Zendcon scaling magentoZendcon scaling magento
Zendcon scaling magento
 
PHP Sessions and Non-Sessions
PHP Sessions and Non-SessionsPHP Sessions and Non-Sessions
PHP Sessions and Non-Sessions
 
Damn Simics
Damn SimicsDamn Simics
Damn Simics
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability Systems
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
 
performance optimization: Memory
performance optimization: Memoryperformance optimization: Memory
performance optimization: Memory
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
Caching and tuning fun for high scalability
Caching and tuning fun for high scalabilityCaching and tuning fun for high scalability
Caching and tuning fun for high scalability
 
ECECS 472572 Final Exam ProjectRemember to check the errata
ECECS 472572 Final Exam ProjectRemember to check the errata ECECS 472572 Final Exam ProjectRemember to check the errata
ECECS 472572 Final Exam ProjectRemember to check the errata
 
ECECS 472572 Final Exam ProjectRemember to check the errat.docx
ECECS 472572 Final Exam ProjectRemember to check the errat.docxECECS 472572 Final Exam ProjectRemember to check the errat.docx
ECECS 472572 Final Exam ProjectRemember to check the errat.docx
 
ECECS 472572 Final Exam ProjectRemember to check the err.docx
ECECS 472572 Final Exam ProjectRemember to check the err.docxECECS 472572 Final Exam ProjectRemember to check the err.docx
ECECS 472572 Final Exam ProjectRemember to check the err.docx
 
PHP 7 OPCache extension review
PHP 7 OPCache extension reviewPHP 7 OPCache extension review
PHP 7 OPCache extension review
 
Caching with Memcached and APC
Caching with Memcached and APCCaching with Memcached and APC
Caching with Memcached and APC
 

More from julien pauli

Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019julien pauli
 
PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machinejulien pauli
 
Basics of Cryptography - Stream ciphers and PRNG
Basics of Cryptography - Stream ciphers and PRNGBasics of Cryptography - Stream ciphers and PRNG
Basics of Cryptography - Stream ciphers and PRNGjulien pauli
 
Mastering your home network - Do It Yourself
Mastering your home network - Do It YourselfMastering your home network - Do It Yourself
Mastering your home network - Do It Yourselfjulien pauli
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesjulien pauli
 
Php and threads ZTS
Php and threads ZTSPhp and threads ZTS
Php and threads ZTSjulien pauli
 
Symfony live 2017_php7_performances
Symfony live 2017_php7_performancesSymfony live 2017_php7_performances
Symfony live 2017_php7_performancesjulien pauli
 
Profiling php5 to php7
Profiling php5 to php7Profiling php5 to php7
Profiling php5 to php7julien pauli
 
PHP 7 performances from PHP 5
PHP 7 performances from PHP 5PHP 7 performances from PHP 5
PHP 7 performances from PHP 5julien pauli
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13julien pauli
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)julien pauli
 
Communications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHPCommunications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHPjulien pauli
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from insidejulien pauli
 
PHPTour-2011-PHP_Extensions
PHPTour-2011-PHP_ExtensionsPHPTour-2011-PHP_Extensions
PHPTour-2011-PHP_Extensionsjulien pauli
 
PHPTour 2011 - PHP5.4
PHPTour 2011 - PHP5.4PHPTour 2011 - PHP5.4
PHPTour 2011 - PHP5.4julien pauli
 

More from julien pauli (20)

Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019
 
Php engine
Php enginePhp engine
Php engine
 
Dns
DnsDns
Dns
 
PHP Internals and Virtual Machine
PHP Internals and Virtual MachinePHP Internals and Virtual Machine
PHP Internals and Virtual Machine
 
Basics of Cryptography - Stream ciphers and PRNG
Basics of Cryptography - Stream ciphers and PRNGBasics of Cryptography - Stream ciphers and PRNG
Basics of Cryptography - Stream ciphers and PRNG
 
Mastering your home network - Do It Yourself
Mastering your home network - Do It YourselfMastering your home network - Do It Yourself
Mastering your home network - Do It Yourself
 
SymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performancesSymfonyCon 2017 php7 performances
SymfonyCon 2017 php7 performances
 
Php and threads ZTS
Php and threads ZTSPhp and threads ZTS
Php and threads ZTS
 
Tcpip
TcpipTcpip
Tcpip
 
Symfony live 2017_php7_performances
Symfony live 2017_php7_performancesSymfony live 2017_php7_performances
Symfony live 2017_php7_performances
 
Profiling php5 to php7
Profiling php5 to php7Profiling php5 to php7
Profiling php5 to php7
 
PHP 7 performances from PHP 5
PHP 7 performances from PHP 5PHP 7 performances from PHP 5
PHP 7 performances from PHP 5
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
PHP Tips for certification - OdW13
PHP Tips for certification - OdW13PHP Tips for certification - OdW13
PHP Tips for certification - OdW13
 
PHP5.5 is Here
PHP5.5 is HerePHP5.5 is Here
PHP5.5 is Here
 
Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)Php in 2013 (Web-5 2013 conference)
Php in 2013 (Web-5 2013 conference)
 
Communications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHPCommunications Réseaux et HTTP avec PHP
Communications Réseaux et HTTP avec PHP
 
Quick tour of PHP from inside
Quick tour of PHP from insideQuick tour of PHP from inside
Quick tour of PHP from inside
 
PHPTour-2011-PHP_Extensions
PHPTour-2011-PHP_ExtensionsPHPTour-2011-PHP_Extensions
PHPTour-2011-PHP_Extensions
 
PHPTour 2011 - PHP5.4
PHPTour 2011 - PHP5.4PHPTour 2011 - PHP5.4
PHPTour 2011 - PHP5.4
 

Recently uploaded

activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxUdaiappa Ramachandran
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-pyJamie (Taka) Wang
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 

Recently uploaded (20)

20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
Building AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptxBuilding AI-Driven Apps Using Semantic Kernel.pptx
Building AI-Driven Apps Using Semantic Kernel.pptx
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
20230202 - Introduction to tis-py
20230202 - Introduction to tis-py20230202 - Introduction to tis-py
20230202 - Introduction to tis-py
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 

Understanding PHP memory

  • 2. Hello everybody  Julien PAULI  Programming with PHP since early 2000s  Programming in C  PHP Internals programmer/reviewer  PHP 5.5 & 5.6 Release Manager  @julienpauli  Tech blog at jpauli.github.io  jpauli@php.net
  • 3. What about you ?  Got some Unix/Linux understandings ?  Have already experienced C programming ?  Have already experienced PHP programming ?
  • 4. What we'll cover together  Memory , what's that ?  bytes, stack, heap, etc.  Measuring a process memory consumption  memory image map analysis  Understanding PHP memory consumption  Zend Memory Manager coming  Measuring PHP memory consumption  from PHP land or from system land
  • 7. Memory in a user process  The Virtual Memory image is divided in segments  text  data  heap  stack
  • 8. Memory usage can grow  Stack will grow as functions will get called  And will narrow as the calls stop and return  Heap will grow as the programmer will decide  Using dynamic allocation functions (malloc, mmap)  Programmer has to free memory by hand  If not : memory leak
  • 10. Linux memory monitoring  'top' or /proc FS > cat /proc/28754/status VmPeak: 20452 kB VmSize: 20324 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 316 kB VmRSS: 316 kB VmData: 16440 kB VmStk: 136 kB VmExe: 4 kB VmLib: 1664 kB VmPTE: 28 kB VmSwap: 0 kB Size of the VM map (out of total mem) Resident Set Size : Size actually in PM Size of the data segment in VM Size of the stack segment in VM Size of the text segment in VM pid
  • 11. Going even deeper  Let's show the detailed process memory map : > cat /proc/28754/smaps shared segment private mem shared mem
  • 12. PHP !
  • 13. PHP, just a process  PHP is just a process like any other  You then can monitor its memory usage by asking the OS <?php passthru(sprintf('cat /proc/%d/status', getmypid())); <?php function heap() { return shell_exec(sprintf('grep "VmRSS:" /proc/%d/status', getmypid())); }
  • 14. The PHP model Startup Shutdown Request #1 Request #2 Request #3 Startup Shutdown Request #1 Request #2 Request #3 php-fpm worker#1 php-fpm worker#2
  • 15. The PHP model  One same process may treat many requests  If the process leaks memory, you'll suffer from that  Request n+1 must know nothing about request n  Need to "flush" the request-allocated memory  Need to track request-bound memory claims  ZendMM is the layer that does the job  Share-nothing architecture : by design.
  • 16. Inside PHP  PHP internal request-bound heap allocator : Zend Memory Manager
  • 17. Why a custom layer ?  ZendMM  Allows monitoring of request-bound heap usage by basically counting malloc/free calls  Allows the PHP user to limit the heap mem usage  Allows caching of alloced blocks to prevent memory fragmentation and syscalls  Allows preallocating blocks of well-known-sizes for PHP internal structures to fit-in in an aligned way  Ease memory leaks debugging in core and exts
  • 18. ZendMM guards and leak tracker  Only works in debug mode PHP  report_memleaks=1 in php.ini  Does NOT replace valgrind
  • 19. Zend MM test script <?php ini_set('memory_limit', -1); /* unlimited ZendMM heap */ function heap() { return shell_exec(sprintf('grep "VmRSS:" /proc/%d/status', getmypid())); } echo heap(); $a = range(1, 1024*1024); /* Stress memory by allocating */ echo heap(); unset($a); /* Stress memory by freeing */ echo heap();
  • 20. Zend MM launch test > time USE_ZEND_ALLOC=1 php zendmm.php VmRSS: 9640 kB VmRSS: 159296 kB VmRSS: 10068 kB real 0m0.237s user 0m0.148s sys 0m0.080s > time USE_ZEND_ALLOC=0 php zendmm.php VmRSS: 9608 kB VmRSS: 148988 kB VmRSS: 140804 kB real 0m0.288s user 0m0.176s sys 0m0.108s
  • 21. Valgrind tests for Symfony2 command  app/console runs lots of PHP code under SF2 >USE_ZEND_ALLOC=1 valgrind php app/console debug:container total heap usage: 84,000 allocs, 84,000 frees, 25,966,154 bytes allocated >USE_ZEND_ALLOC=0 valgrind php app/console debug:container total heap usage: 813,570 allocs, 813,570 frees, 74,579,732 bytes allocated
  • 23. ZendMM benefits  Better memory management  More memory efficient  Far less malloc/free calls  Less context switches, less Kernel stress  Less CPU usage  Less heap fragmentation / compaction  A PHP ~10% faster with ZendMM enabled  Really depends on use-case
  • 24. Memory manager internals  Layer on top of the heap  Will allocate memory from the heap by chunks of customizable size (segments)  Will use a customizable low level heap (malloc / mmap)
  • 25. A quick word on ZendMM internals  ZEND_MM_SEG_SIZE env variable to customize segment size  Must be power-of-two aligned  Default value is 256Kb
  • 26. ZendMM in PHP user land  memory_limit (INI setting)  memory_get_usage(true)  Returns the size of all the allocated segments  memory_get_usage()  Returns the occupied size in all the allocated segments  memory_get_[peak]_usage([real])  Returns the max memory that has been allocated/used. Could have been freed meantime
  • 28. ini_set('memory_limit', -1); // unlimited memory function get_mem_stats() { printf("Memory usage %.2f Kbn", memory_get_usage() / 1024); if ($segSize = getenv('ZEND_MM_SEG_SIZE')) { printf("Heap segmentation : %d segments of %d bytes (%d Kb used)n", memory_get_usage(1)/$segSize, $segSize, memory_get_usage(1)/1024); } } get_mem_stats(); $a = str_repeat('a', 1024*1024*10); // 10 Mb get_mem_stats(); Adjusting heap segment size
  • 29. Adjusting heap segment size  Segment size = 256Kb (default value)  Segment size = 4Mb $> ZEND_MM_SEG_SIZE=262144 php /tmp/mem.php Memory usage 221.26 Kb Heap segmentation : 1 segments of 262144 bytes (256 Kb used) Memory usage 10461.47 Kb Heap segmentation : 42 segments of 262144 bytes (10752 Kb used) get_mem_stats(); $a = str_repeat('a', 1024*1024*10); // 10 Mb get_mem_stats(); $> ZEND_MM_SEG_SIZE=4194304 php /tmp/mem.php Memory usage 221.26 Kb Heap segmentation : 1 segments of 4194304 bytes (4096 Kb used) Memory usage 10461.47 Kb Heap segmentation : 4 segments of 4194304 bytes (16384 Kb used)
  • 30. memory_get_usage() ?  memory_get_usage() tells you how much your allocated blocs consume  They usually don't fill their segment entirely  Thus memory_get_usage(true) shows more  This doesn't count stack  This does only count request-bound memory  This doesn't count linked libraries present in the process memory map  This doesn't show non-request-bound memory
  • 31. Real memory image  valgrind massif
  • 32. Massif memory monitoring -------------------------------------------------------------------------------- n time(ms) total(B) useful-heap(B) extra-heap(B) stacks(B) -------------------------------------------------------------------------------- 0 0 0 0 0 0 1 309 56 37 19 0 2 341 384 357 27 0 3 376 1,343,992 1,340,371 3,621 0 4 408 1,360,480 1,355,289 5,191 0 5 443 1,376,512 1,367,265 9,247 0 6 471 1,753,976 1,735,671 18,305 0 7 505 2,345,152 2,275,927 69,225 0 8 535 2,405,224 2,329,798 75,426 0 9 570 2,433,408 2,348,849 84,559 0 10 613 2,592,912 2,461,650 131,262 0 11 657 2,681,240 2,534,247 146,993 0
  • 33. Massif details 94.52% (2,534,247B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc. ->39.11% (1,048,576B) 0x87A7BB: zend_interned_strings_init (zend_string.c:48) | ->17.70% (474,464B) 0x866449: _zend_hash_quick_add_or_update (zend_alloc.h:95) | ->16.48% (441,936B) 0x85F66D: zend_register_functions (zend_API.c:2138) | ->11.93% (320,000B) 0x878625: gc_init (zend_gc.c:124) | ->11.93% (320,000B) 0x8585DF: OnUpdateGCEnabled (zend.c:82) | ->11.93% (320,000B) 0x86E353: zend_register_ini_entries (zend_ini.c:208)
  • 34. Recommendations / statements  Understand memory_get_usage()  It only shows request-bound allocations, not persistent allocations (that reside through requests)  PHP extensions may allocate persistent memory  Do NOT activate extensions you will not use  Libraries used by PHP may also allocate persistent memory  Use your OS to monitor your process memory accurately
  • 35. Playing with memory in PHP user land
  • 36. Master your PHP mem usage  In PHP land ...  all variable types consume memory  every script asked for compilation will eat memory  This memory will be allocated using ZendMM  The memory for parsed script is freed when the request ends  The memory for user variable is freed when the data is not used any more  And here comes the challenge  When isn't the data needed any more ??
  • 37. Compilation eats memory  Compiling a script eats request-bound memory  If you compile a class, that eats lots of memory  You'd better use that class at runtime  Use an autoloader to be sure <?php $mem = memory_get_usage(); require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../src/Symfony/Component/DependencyInjection/ContainerBuilder.php' echo memory_get_usage() - $mem . "n"; php app/bar.php 246,692
  • 38. PHP Variables  Variables are internally zval structs
  • 39. PHP Variables  What eats memory is what is stored into the zval, not really the zval itself :  A huge string  Tip : a file_get_contents('huge-file') is a huge string  A complex array or object  Resources don't really consume mem in zval <?php /* This consumes sizeof(zval) + 1024 bytes */ $a = str_repeat('a', 1024);
  • 40. PHP Variables  What you want to avoid is have PHP duplicate the zval  But PHP is kind about that  What you want to happen in PHP freeing the memory ASAP  Should you know when PHP duplicates or frees zval , that's the most important !
  • 41. zvals and refcount  PHP simply counts how many symbols (PHP vars) point to a zval  This is called the refcount <?php $a = "foo"; $b = $a;
  • 42. zvals and refcount  PHP uses a CopyOnWrite (COW) system for zvals  Memory is saved  Memory gets allocated only on changes <?php $a = "foo"; $b = $a; $a = 17;
  • 43. zvals and refcount  PHP frees memory for a zval when its refcount reaches 0  Yes, unset() just refcount-- , that's all <?php $a = "foo"; $b = $a; $c = $b; $b = "bar"; unset($a);
  • 44. No references needed  You see how smart PHP is with memory ?  It's been designed with that in mind  No references needed to hint PHP !  Don't try to hint PHP with references  References can lead to adverse effects  Force PHP to copy a zval  Prevents PHP from freeing memory of a zval &
  • 45. Tracking refcount  xdebug_debug_zval()  symfony_zval_info() namespace Foo; class A { public $var = 'varA'; } $a = new A(); xdebug_debug_zval('a'); a: (refcount=1, is_ref=0)=class FooA { public $var = (refcount=2, is_ref=0)='varA'; }
  • 46. Tracking refcount namespace Foo; class C { public $b; public function __construct(B $b) { $this->b = $b; } } $c = new C($b = new B); xdebug_debug_zval('c'); c: (refcount=1, is_ref=0)=class FooC { public $b = (refcount=2, is_ref=0)=class FooB { } } namespace Foo; class B { } unset($b); xdebug_debug_zval('c'); c: (refcount=1, is_ref=0)=class FooC { } c: (refcount=1, is_ref=0)=class FooC { public $b = (refcount=1, is_ref=0)=class FooB { } } unset($c->b); xdebug_debug_zval('c');
  • 47. Garbage collector ?  As of PHP5.3 , a garbage collector exists  Used to free circular references  And that's all !  PHP already frees itself your vars as their refcount reaches 0  And it's always been like that
  • 48. Circular references $a = new A; $b = new B (object) 'A' refcount = 1 $a (object) 'B' refcount = 1 $b
  • 49. Circular references $a->b = $b; $b->a = $a; (object) 'A' refcount = 2 $a (object) 'B' refcount = 2 $b $b->a $a->b
  • 50. Circular references  Objects are still in memory but no more PHP var point to them  We can call that a "PHP Userland memory leak" unset($a, $b); (object) 'A' refcount = 1 $b->a (object) 'B' refcount = 1 $a->b
  • 51. Garbage collector $a = new A; $b = new B; $a->b = $b; $b->a = $a; unset($a, $b); echo gc_collect_cycles(); // 2
  • 53. PHP references main line  Using references (&) in PHP can really fool you  They usually force the engine to duplicate memory containers  Which is bad for performance  Especially when the var container is huge
  • 54. References mismatch <?php function foo($data) { echo "in function : " . memory_get_usage() . "n"; } echo "Initial memory : " . memory_get_usage() . "n"; $r = range(1, 1024); echo "Array created : " . memory_get_usage() . "n"; foo($r); echo "End of function " . memory_get_usage() . "n"; Initial memory : 227.136 Array created : 374.912 in function : 374.944 End of function 374.944
  • 55. References mismatch <?php function foo($data) { echo "in function : " . memory_get_usage() . "n"; } echo "Initial memory : " . memory_get_usage() . "n"; $r = range(1, 1024); $r2 = &$r; echo "Array created : " . memory_get_usage() . "n"; foo($r); echo "End of function " . memory_get_usage() . "n"; Initial memory : 227.208 Array created : 375.096 in function : 473.584 End of function 375.128
  • 56. When does the engine separate ?  In any mismatch case : zval passed to function arginfo decl. zval received in function separated by engine? is_ref=0 refcount = 1 pass_by_ref=0 is_ref=0 refcount = 2 NO is_ref=1 refcount > 1 pass_by_ref=0 is_ref=1 refcount =1 YES is_ref=0 refcount > 1 pass_by_ref=0 is_ref=0 refcount > 1 ++ NO is_ref=0 refcount = 1 pass_by_ref=1 is_ref=1 refcount = 2 YES is_ref=1 refcount > 1 pass_by_ref=1 is_ref=1 refcount > 1 ++ NO is_ref=0 refcount > 1 pass_by_ref=1 is_ref=1 refcount = 2 YES
  • 57. Symfony_debug to notice mismatches  https://github.com/symfony/debug function bar($var) { } $a = "foo"; $b = &$a; bar($a); Notice: Separating zval for call to function 'bar' in /tmp/memory.php on line 20
  • 59. Foreach separation behavior  It happens sometimes foreach() duplicates your variable for iteration  This will eat performances in case of big or complex arrays being iterated  There is nothing special to say about objects implementing Traversable  The behavior is then just yours
  • 60. foreach iterating array #1  If the variable has a refcount of 1, no duplication is performed by foreach() $a = range(1,1024); echo memory_get_usage() . "n" ; foreach ($a as $v) { if ($v == 1) { echo memory_get_usage() . "n" ; } } echo memory_get_usage() . "n" ; 373936 374056 374056
  • 61. foreach iterating array #2  If the variable has a refcount >1, foreach() will duplicate it fully for iteration $a = range(1,1024); $b = $a; echo memory_get_usage() . "n" ; foreach ($a as $v) { if ($v == 1) { echo memory_get_usage() . "n" ; } } echo memory_get_usage() . "n" ; 373936 472512 374056
  • 62. foreach iterating array #3  If the variable is a reference, foreach() will work onto that array and won't perform duplication $a = range(1,1024); $b = &$a; echo memory_get_usage() . "n" ; foreach ($a as $v) { if ($v == 1) { echo memory_get_usage() . "n" ; } } echo memory_get_usage() . "n" ; 373936 374056 374056
  • 63. Monitoring memory usage  Not much tools exist (for PHP)  memory_get_usage()  OS' help (/proc , pmap , etc...)  Valgrind with massif tool  PHP Extensions  Xdebug  memprof  memtrack
  • 64. Quick intro to memprof  https://github.com/arnaud-lb/php-memory-profiler $b = range(1, 1024 * 1024); /* a lot of memory */ $b[] = foo(); loader('/Zend/Date.php'); /* a lot of PHP source code */ memprof_dump_callgrind(fopen('/tmp/trace.out', 'w'));
  • 65. Thank you for listening