How can I solve the c10k problem if I use PHP?

I decide the architecture of the application, where "Http KeepAlive" and "long poll" will be used for a quicker response. Is there anything for PHP that solves the problem that Tornado does for c10k?

I was thinking about using nginx + PHP-FPM. But then for 1000 active connections there won't be 1000 PHP-FPM processes?

Then I think that we will have the same problem as Apache with many persistent connections. Is not it?

EDIT: I understand that nginx will be enough if I just want HTTP KeepAlive. But what if I also want a long survey, like a tornado? Is there something similar in PHP?

+6
source share
3 answers

For active connections (for example, loading and running a specific PHP script), yes, there will be as many PHP processes as there are active connections. But KeepAlive are passive connections, and Nginx does very well with KeepAlive passive connections with very low resource usage - even for thousands of them.

The problem with Apache is that it, in the normal configuration with mod_php and mpm_prefork, needs a process for every connection, even if it's just a passive KeepAlive. This means that most Apache servers should actually have a PHP process in memory, even if the connection is passive, but this is not the case if you run PHP as FastCGI. Apache can also handle many passive connections if you run PHP as FastCGI and choose mpm_worker, which will create an easier stream for each connection, but it is still not as good as Nginx.

+6
source

My answer to this would be to take a look at node.js , you indicate the active 100K connections that are Node. js should work fine if you have the right hardware.

Node does not spawn new processes when connected, the socket is placed in the queue system, but it is not a typical queue system, where one connection is processed, and then the next.

node.js is notorious for handling a large number of connections, and there the HTTP client-client library is based on the Keep-Alive transfer style, as well as very fast and powerful.

I used it fairly honestly and I have to say that it is extremely easy to use, it is based on the Super fast Google V8 Engine, which is used for JavaScript in Chrome, which means it is very fast, you really have to take a look at it, and you will see that it is viable for this kind of thing.

+2
source

I do not understand what do you mean. c10k is connected to the web server (apache, nginx, etc.), not PHP.

If you are using nginx, you should not worry about it.

0
source

Source: https://habr.com/ru/post/889201/


All Articles