I am wondering, what goes behind the scenes when simultaneous requests are served by php(apache2).
If it's a multithreaded model, How are the threads managed and what is the bench mark of the concurrent requests.
PHP does not handle requests. The web server does. For Apache HTTP Server , the most popular is "mod_php". This module is actually PHP itself, but compiled as a module for the web server, and so it gets loaded right inside it.
Requests are handled in parallel by the web server (which runs the PHP script). Updating data in the database is pretty fast, so any update will appear instantaneous, even if you need to update multiple tables.
PHP, like most server-side languages, uses multi-threaded, blocking I/O to carry out multiple tasks in parallel.
PHP applications can create, read, write, execute and synchronize with Threads, Workers and Threaded objects. This extension is considered unmaintained and dead. Consider using parallel instead. The pthreads extension cannot be used in a web server environment.
The correct answer is: PHP is able to do both, and so can Apache.
With the prefork mpm, a multi-process model is used, several instances of apache are forked upon server startup which in turn initialize the PHP interpreter, one interpreter for every process.
With the worker mpm, the model is thread based; there can be as little as one process, for each thread that Apache initializes, it again initializes a PHP interpreter.
In either mode, the instances of the interpreter are isolated from one another, in prefork mode because that's the way forking works, and in worker mode because of TSRM, an omnipresent part of PHP that nobody really talks about.
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