Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how are concurrent requests handled in PHP (using - threads, thread pool or child processes)

I understand that PHP supports handling multiple concurrent connections and depending on server it can be configured as mentioned in this answer

How does server manages multiple connections does it forks a child process for each request or does it handle using threads or does it handles using a thread pool?

The linked answer says a process is forked and then the author in comment says threads or process, which makes it confusing, if requests are served using child-processes, threads or thread pool?

like image 462
prasun Avatar asked Nov 10 '15 07:11

prasun


People also ask

Can PHP handle concurrent requests?

The more concurrent requests limit you have the more calls you can have active in parallel, and the faster you can scrape. Making concurrent requests in PHP is as easy as creating threads for our scraping functions!

How many concurrent requests can PHP handle?

Of course, the maximum number of processes is 10. No matter how many concurrent requests you have, only 10 processes can handle the requests.

What are concurrent requests?

When a user runs a report, a request to run the report is generated. The command to run the report is a concurrent request. The program that generates the report is a concurrent program. Concurrent programs are started by a concurrent manager.

Should PHP download thread safe?

Thread-safety is recommended when the web server run multiple threads of execution simultaneously for different requests. In Thread Safety binary can work in a multi-threaded web server context. Thread Safety works by creating a local storage copy in each thread so that the data will not collide with another thread.


1 Answers

As I know, every webserver has it's own kind of handling multpile simultanous request. Usually Apache2 schould fork a child process for each new request. But you can somehow configure this behaviour as mentioned in your linked StackOverflow answer.

Nginx for example gets every request in one thread (processes new connections asyncronously like Node.js does) or sometimes uses caching (as configured; Nginx could also be used as a load balancer or HTTP proxy). It's a thing of choosing the right webserver for your application.

Apache2 could be a very good webserver but you need more loadbalancing when you want to use it in production. But it also has good power when having multiply short lasting connections or even documents which don't change at all (or using caching).

Nginx is very good if you expect many long lasting connections with somehow long processing time. You don't need that much loadbalancing then.

I hope, I was able to help you out with this ;)

Sources:

https://httpd.apache.org/docs/2.4/mod/worker.html

https://anturis.com/blog/nginx-vs-apache/

I recommend you to also look at: What is thread safe or non-thread safe in PHP?

like image 112
jankal Avatar answered Oct 06 '22 12:10

jankal