Make sure you have PHP8.x installed and setup to use on Cli, using php -v
(For Docker Images check Swoole / OpenSwoole Official Documentation)
sudo apt-get update
sudo apt install gcc -y && \
sudo apt-get install libssl-dev -y && \
sudo apt install openssl -y && \
sudo apt install build-essential -y && \
sudo apt-get install bzip2 -y && \
sudo apt-get install zlib1g-dev -y && \
sudo apt-get install libzip-dev -y && \
sudo apt-get install autoconf -y && \
sudo apt install libpcre3-dev -y && \
sudo apt-get install -y libc-ares2 -y && \
sudo apt install libc-ares-dev -y && \
sudo apt-get install libpq-dev -y && \
sudo apt-get install libcurl4-openssl-dev -y && \
sudo apt-get install inotify-tools -y && \
sudo apt install libbrotli-dev -y
pecl install -D 'enable-sockets="yes" enable-openssl="yes" enable-http2="yes" enable-mysqlnd="yes" enable-swoole-json="no" enable-swoole-curl="yes" enable-cares="yes"' swoole
if /tmp directory not created, then create it as below
sudo mkdir -m 775 /tmp
To install Swoole on PHP 8.3, use command below (For a different version of php replace all instances of '8.3' in command below with your version of php)
cd /tmp && \
git clone https://github.com/swoole/swoole-src && \
cd swoole-src && \
git checkout v5.1.3 && \
phpize8.3 clean && \
phpize8.3 && \
./configure --enable-openssl \
--enable-mysqlnd \
--enable-sockets \
--enable-swoole-curl \
--enable-swoole-pgsql \
--enable-debug \
--enable-debug-log \
--enable-trace-log \
--enable-thread-context \
--enable-cares \
--with-php-config=/usr/bin/php-config8.3 && \
sudo make clean && make && sudo make install && \
sudo bash -c "cat > /etc/php/8.3/mods-available/swoole.ini << EOF
; Configuration for OpenSwoole
; priority=25
extension=swoole
swoole.enable_preemptive_scheduler=On
EOF"
sudo phpenmod -s cli -v 8.3 openswoole
sudo pear channel-update pear.php.net && \
sudo pecl channel-update pecl.php.net && \
sudo pecl install -D 'enable-sockets="yes" enable-openssl="yes" enable-http2="yes" enable-mysqlnd="yes" enable-swoole-pgsql="yes" with-postgres="yes" enable-swoole-json="yes" enable-hook-curl="yes" enable-swoole-curl="yes" enable-debug="yes" enable-swoole-trace="yes" enable-thread-context="yes" enable-debug-log="yes" enable-trace-log="yes" enable-cares="yes"' openswoole-22.1.2 && \
sudo bash -c "cat > /etc/php/8.3/mods-available/openswoole.ini << EOF
; Configuration for OpenSwoole
; priority=25
extension=openswoole
openswoole.enable_preemptive_scheduler=On
openswoole.use_shortname=On
swoole.use_shortname=On
EOF" && \
sudo phpenmod -s cli -v 8.3 openswoole
composer require openswoole/core:22.1.5
git clone https://github.com/fakharak/swoole-serv.git
composer install
composer dump-autoload
cd to swoole-serv folder, and then run the command below;
php sw_service.php websocket
sudo php ./websocketclient/websocketclient_usage.php
php sw_service.php reload
sudo php ./websocketclient/websocketclient_usage.php reload-code
php sw_service.php shutdown
php sw_service.php restart
kill -USR1 `cat server.pid`
kill -USR2 `cat server.pid`
sudo kill -SIGTERM $(sudo lsof -t -i:9501)
OR
sudo kill -15 $(sudo lsof -t -i:9501)
OR
kill -15 [process_id]]
OR (specially when daemon = 1 (daemonize mode))
sudo kill `cat server.pid`
sudo phpdismod -s cli swoole && \
sudo phpenmod -s cli openswoole
sudo phpdismod -s cli openswoole && \
sudo phpenmod -s cli swoole
ps -aux | grep swool
ps faux | grep -i sw_service.php
sudo lsof -t -i:9501