Search code examples
phpnginxwebsocketfile-descriptorratchet

File limits with PHP WebSocket Server and NGINX reverse proxy


I have set up a PHP websocket server (Ratchet) and use NGINX as a reverse proxy to avoid having users connect to a different port. Everything goes great until I get a little less than 1024 (1020 to be exact) connections. Then every other connection is denied (times out). It looks like something's capped at 1024 file descriptors, but I can't figure out what.

NGINX's proxy_error_log says that "upstream timed out (110: Connection timed out) while reading response header from upstream, client: my_ip, server: "domain_name", request: "GET /socket_server_path/ HTTP/1.1", upstream: "http://127.0.0.1:8080/socket_server_path/", host: "domain_name_again"

The NGINX user and the user running the server both have a good file limit set in /etc/security/limits.conf (higher than 1024). From what I can tell the processes have a high limit set in /proc/PID#/limit.

https://github.com/ratchetphp/Ratchet/issues/300 describes what I imagine is happening, but I don't see that error printing in my application. I went ahead and compiled PHP with --enable-fd-setsize=10000 anyway, but that still doesn't let more connections happen.

How can I get more details around this and understand what exactly is happening? All I have to go on right now is that NGINX is timing out. But I don't know if PHP is unable to open more sockets, or if it's NGINX, or something completely different.


Solution

  • It turns out I was just a dummy. According to https://bugs.php.net/bug.php?id=69637 --enable-fd-setsize doesn't work as well as it should.

    And even though I changed the system header file constants (mentioned in the Ratchet issue linked in my original question), I had re-compiled without running 'make clean', so I guess I was still compiling with the old (low limit) values.

    I wasn't able to find anything in my php configuration related to this. But after changing the constants in the header files and compiling again, I was able to get over the 1024 max.