Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does PHP as a CGI handle memory?

When running 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 persists for generally 500-1000 requests before it's restarted.

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

Lets say I have a file that loads a massive library, will it load (then dump) the large library every request or keep it loaded for each new request I pass it?

By "loaded" I mean the classes are included (and parsed) but no objects are created.

How does APC play into this?

like image 927
Xeoncross Avatar asked Aug 29 '11 18:08

Xeoncross


1 Answers

For FCGI (PHP-FPM is FCGI as well), only the php binary and it's binary libraries stay in memory. The PHP user-code does not.

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

Kicks them off, get's them new on a new request. You can easily test that by setting global variables, they are gone at the beginning of the new request.

So the answer to your (bold) question is Let's straight-forward answer: Yes, it get's loaded and dumped per each request, no or! :)

APC does the same. I need to research a link, there is a webserver written in PHP so it can keep everything in memory. Give's you the real speed, however your applications code must properly deal with the changed request logic then.

like image 172
hakre Avatar answered Oct 05 '22 03:10

hakre