On 18 September 2026 09:53:35 BST, David Maye Kitenge <[email protected]> wrote: > * I understand that PHP lifecycle goes something like MINIT() -> RINIT() -> > YOUR_CODE() -> RSHUTDOWN -> MSHUTDOWN. But reading the PHP Lifecycle from PHP > Internals Book > <https://www.phpinternalsbook.com/php7/extensions_design/php_lifecycle.html>. > I got some doubts: in a PHP-CLI, do you have a single instance of the > lifecycle, or a bunch of those per requests? The book says that PHP-CLI uses > a process-based model for parallelism. Is it enabled by default?
I think "process-based model for parallelism" here basically means "any parallelism is somebody else's problem": if you run a PHP script on the command-line, PHP just runs that script in its own process, it doesn't know or care what other processes are running at the same time. > In the case I use an NGINX server as a reverse proxy for the PHP code, and I > run PHP as continuously running through a service/task manager (i.e creating > a systemd entry for PHP to run in the background), will the process-based > parallelism model work by default? "Continuously running" in this case really just means "if the process exits, run it again". PHP doesn't know that's going to happen, and is still running the same code as if you ran it manually. You could set it up to run two copies, or 100; or run the same script through multiple copies of PHP (e.g. in a CI environment); each script will still just be doing its thing. > * Is there a problem that a NTS PHP invokes a C class that handles threads? > Or is it recommendable to build the PHP version as ZTS (Which, based on some > diagram I saw, makes more sense. But I read that it is discouraged as it is a > very hard work to maintain). If the aim is ultimately to run the user's PHP code in a separate thread for each request, you're going to need ZTS - otherwise code in one thread will affect or even crash code in another. A common alternative is to use *asynchronous* request handling rather than *parallel* request handling: a single thread switches context while waiting for things like I/O. For that, you don't need any thread safety, because requests are all in one thread. I hope that helps, Rowan Tommins [IMSoP]
