Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does php handle concurrent requests in multithreaded or multiprocess manner?

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.

like image 998
Yogesh lele Avatar asked Dec 29 '13 16:12

Yogesh lele


People also ask

Can PHP handle 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.

How does PHP handle multiple requests?

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.

Is PHP a single or multi threaded language?

PHP, like most server-side languages, uses multi-threaded, blocking I/O to carry out multiple tasks in parallel.

Are there threads in PHP?

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.


1 Answers

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.

like image 163
Joe Watkins Avatar answered Sep 28 '22 06:09

Joe Watkins