Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limited to 1024 concurrent connections #104

Open
i3bitcoin opened this issue Sep 8, 2017 · 7 comments
Open

Limited to 1024 concurrent connections #104

i3bitcoin opened this issue Sep 8, 2017 · 7 comments

Comments

@i3bitcoin
Copy link

Hi,

It seems that php sockets module can maximum hold 1024 connections.
Is there any way to raise this limitation?

@ghedipunk
Copy link
Owner

Try experimenting with the limits on your server. PHP's Sockets functions are little more than wrappers around the C standard library BSD Sockets, which rely heavily on the OS's settings.

This might help: https://stackoverflow.com/questions/410616/increasing-the-maximum-number-of-tcp-ip-connections-in-linux

@i3bitcoin
Copy link
Author

i3bitcoin commented Sep 9, 2017

My sysctl.conf is properly configured and limits.conf also.
I'm using cloudflare and the support replied that there are no limits on ws.

@i3bitcoin
Copy link
Author

i3bitcoin commented Sep 12, 2017

Okay, I've found that my PHP Sockets server is accepting more than 1024 sockets when I run it from the root.

I'm starting it using this command.
sudo -u www-data php7.0 /path/to/file/

/etc/php/7.0/fpm/php-fpm.conf
rlimit_files = 1048576

/etc/php/7.0/fpm/pool.d/www.conf
rlimit_files = 1048576
listen.backlog = 65536

/etc/security/limits.conf

  • soft nproc 1048576
  • hard nproc 1048576
  • soft nofile 1048576
  • hard nofile 1048576

Any suggestions?

@Xaraknid
Copy link
Collaborator

Xaraknid commented Sep 16, 2017

as @ghedipunk said the problem is core to php ( socket_select ) specificaly not from php-websocket.

To be able to break that limit you'll have to modify the header file in C first then download php from source modify a file in php too then compile it. ( you'll have to undo the header file afterward because it'll affect any other app you install after ). It's a painfull process.

I recommend you to use another backend like epoll. Select was design in another era while massive concurent alive connection not a thing. Select will parse the entire list of connection to know if a client send something in that specific loop, every time, as epoll will only read from client that send actually data.

You'll need to install libev and you can use my version of php-websocket that support libev.

https://github.com/Xaraknid/PHP-Websockets

@aRandomKiwi
Copy link

Hi @Xaraknid ,

Is your fork compatible with PHP7+libev, because im currently using @ghedipunk 's WebSocket class (very great and fast) for a new LMS system for an university but the 1024 limit concurrent connections is too painfull and prevent scalability for big projects...

I started to switch to your fork but there is some issues with the code like the "continue" at line 24 of libev.php, and even after switch the continue with a "return" statement there is theses errors generated from the "doHandshake" method :


Undefined index: sec-websocket-protocol
Undefined variable: subProtocol

I tried to mix @ghedipunk 's working doHandshake with your, it seems to work (no errors) but the websocket server cant read data from clients.

I dont want to use Ratchet WS because its too fat and bloated, i prefer the fast and KISS approach of PHPWebsocket but we are in a dead end right now...

@Xaraknid
Copy link
Collaborator

Hello, the version I updated is not the most uptodate version I have I just never see the interest to upload it as no one seem to use it. I check my code and I comment the continue in my version, as I discover like you that cause problem but removing it was not enought.

I add a few feature in my version and also it's work a little bit different. One last thing I worked on is trying to pass the Autobahn|Testsuite, few test not working.

Let me clean my code of junk files (test purpose & information ) and my server name inside code and I'll publish it. ( It work on php7 ).

@Xaraknid
Copy link
Collaborator

Xaraknid commented Dec 4, 2017

Here my latest version I made.

https://github.com/Xaraknid/PHP-Websockets/tree/revision-2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants