I noticed that whenever I use create_function a name is assigned to the function that looks like:
lambda_N
What's weird is that if I refresh the page that N increases, like lambda_2, lambda_3 etc.
Does that mean that these functions stay in memory across page requests? Does the memory explode if I create like 20.000 functions like these?
With mod_php the lifetime of the executor (which representes the state of the php interpreter) is longer than the lifetime of a request since the executor is stored in the memory of the apache process. The apache process isn't terminated by default so it can handle new requests after the old request is finished. Basically each apache process has its own executor.
The number N in \0lambda_N must be unique for each executor since this is the name of the function in the function table (which is also stored per executor). The number N is generated from a counter named lambda_count stored in the _zend_executor_globals structure. It gets incremented on each call to create_function.
So if you refresh the page your request gets handled by the same process and the lambda_count seems to increment each time (while experimenting I found out that with refreshing ctrl-f5 or by executing other requests, the number is more random so I assume the process is switches more often).
The short answer is no. Apparently the function table (among other things like the op arrays) is cleaned after each request in the php_request_shutdown callback. As far as I can see the function entry is still in the hash but the functions opcodes are freed (I could've missed the part where the hash-entries are deleted).
So certain members of the executor are shared across multiple requests, but the sensible ones are cleared out.
I'm not sure how the lifetime of the functions are handled if you use fcgi, where the PHP process also serves more than one request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With