reference

Swoole download: github.com/swoole/swoo…

To install

Download the software

Wget https://github.com/swoole/swoole-src/archive/refs/tags/v4.6.4.tar.gz # extract [root @ VM - 0-15 - centos local] # tar ZXVF. - Swoole-src-4.6.4.tar. gz # rename [root@VM-0-15-centos local]# mv swoole-src-4.6.4 swoole-srcCopy the code

Compile the installation

cd swoole-src
/usr/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
Copy the code

Tips:

If your php-config is not installed in /usr/local/php-bin, use find /usr/local/php-bin to search for php-conf

Open the Swoole extension

After a successful compilation installation, you need to enable the swoole extension by adding a line extension=swoole.so to php.ini

extension=swoole.so
Copy the code

Check the test

Expand the view

php -m |grep swoole
swoole
Copy the code

PHP code testing


      
$http = new Swoole\Http\Server("0.0.0.0".9501); 

$http->on("start".function ($server) { 
	echo "Swoole http server is started at http://127.0.0.1:9501\n"; 
});
$http->on("request".function ($request.$response) { 
	$response->header("Content-Type"."text/plain");
	$response->end("Hello World\n"); 
});

$http->start();
Copy the code

PHP then runs the file

[root@VM-0-15-centos swoole_s]# PHP swoole. PHP swoole is started at http://127.0.0.1:9501Copy the code

Browser access