How does PHP handle CGI memory?

When I run PHP with Apache, I know that the php core and all libraries are loaded for each request. However, with PHP CGI, FastCGI, or using PHP-FPM, the php process usually saves 500-1000 requests until it is restarted.

During this time, how does it handle loaded classes or PHP libraries?

Suppose I have a file that loads a massive library, does it load (then unload) a large library every request, or save it for every new request that I transfer?

By β€œloaded,” I mean that classes are included (and parsed), but no objects are created.

How does APC play this?

+7
source share
1 answer

For FCGI (PHP-FPM also uses FCGI), only php binary and binary libraries remain in memory. Custom PHP code does not.

During this time, how does it handle loaded classes or PHP libraries?

Cleans them, getting them new on new request. You can easily verify that by setting global variables, they disappear at the beginning of a new query.

So, the answer to your (bold) question: Let the direct answer: Yes, it is downloaded and reset for each request, no or! :)

APC does the same. I need to examine the link, there is a web server written in PHP so that it can store everything in memory. Give you real speed, however your application code should correctly handle the changed request logic.

+2
source

All Articles