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

前端 未结 3 1321
梦谈多话
梦谈多话 2021-02-11 17:32

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

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-11 17:41

    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?

提交回复
热议问题