apache php > users requests [closed] apache php > users requests [closed] multithreading multithreading

apache php > users requests [closed]


Whilst PHP may be single threaded, Apache can run multi-process and multi-threaded. This allows many requests to be executed simultaneously. You can configure how many simultaneous requests in fact.

You can actually see Apache serving these requests live, see which are waiting, and which are being served via mod_status (http://httpd.apache.org/docs/2.2/mod/mod_status.html).


Apache has multiple threads so multiple PHP scripts can run at once.

Webservers such as Nginx use an event driven architecture. Asynchronous I/O and all that jazz.

Webservers usually have some sort of mechanism to enable them to handle more than 1 request at a time, or at least make it seem like they can.

Apache uses threads, Nginx uses an event loop, but they are not serial in the sense that you want. The reason is very simple: it wastes resources. While your PHP script is waiting for the harddisk to move to the right position so you can read a block from a file you're reading you might as well be doing something else, ie. handle another request that doesn't require I/O right now.

If it's crucial some request finishes before other users make requests you should consider switching to a more decoupled asynchronous architecture. I don't know how invested you are in your current solution. Event handling can be implemented as simply as a simple poll or even a long poll.