Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase php websocket maximum connections

I currently am running a Debian 8 machine with PHP, Apache on it.

On this machine I have installed a ratchet websocket server although I recently went over 1000 concurrent users on the website I am running. This caused problems with the Ratchet socket since at 1020 connections it seems to automatically refuse all new connections.

I already increased the ulimit -n and sortlike for debian itself, but I started to wonder if the problem might be in my php default configuration or the ratchet websocket I am using.

Any ideas on what configuration I should change are highle appreciated.

like image 264
mitchken Avatar asked May 07 '16 20:05

mitchken


2 Answers

You just need to read the official document in the deployement section: it's say:

The libev and libevent projects implement high-performance asynchronous event driven C libraries. The PHP extensions ev and event are available to interface with these libraries. They allow an application to transparently use the best kernel level evented I/O method (select, poll, epoll, kqueue, or event ports) available for the operating system it is running on.

The ev PHP extension bundles the libev C library in its source and requires no prior setup. If you want to use the event PHP extension, you need to first install the libevent library along with its headers for your operating system. For example on Debian/Ubuntu:

-$ sudo apt-get install libevent libevent-dev

You may then install the ev or the event extension, either through your preferred package manager, or directly using pecl:

-$ sudo pecl install ev

-$ sudo pecl install event

No further setup is necessary; if either of these extensions is present, the evented I/O loop toolkit used by Ratchet will automatically utilize them, which will drastically improve concurrency. here is the link: http://socketo.me/docs/deploy

like image 167
Manda Avatar answered Sep 21 '22 08:09

Manda


Make sure libevent is working

if (function_exists('event_base_new')) {
    echo "\033[0m We can use LibEventLoop!!" . PHP_EOL;
} elseif (class_exists('libev\EventLoop', false)) {
    echo "\033[0m We can use LibEvLoop!!" . PHP_EOL;
} elseif (class_exists('EventBase', false)) {
    echo "\033[0m We can use ExtEventLoop!!" . PHP_EOL;
} 
else 
{
    echo "\033[0m We can use StreamSelectLoop!!" . PHP_EOL;
}

php-fpm.conf:

rlimit_files = 65536
rlimit_core = unlimited

OS limits

https://rtcamp.com/tutorials/linux/increase-open-files-limit/

Taken from https://github.com/ratchetphp/Ratchet/issues/376

like image 28
cetver Avatar answered Sep 20 '22 08:09

cetver