Laravel Swoole 安装

pecl install swoole

vi /etc/php/8.0/fpm/php.ini
and
vi /etc/php/8.0/cli/php.ini
extension=swoole.so

php -m | grep swoole


安装laravel-swoole,最好加上 -vvv 参数,因为安装很慢,会给人一种卡住的感觉
composer require swooletw/laravel-swoole -vvv

add the Service Provider to the providers array in config/app.php:
[
    'providers' => [
        SwooleTW\Http\LaravelServiceProvider::class,
    ],
]

generate configuration files swoole_http.php and swoole_websocket.php in directory /config:
php artisan vendor:publish --tag=laravel-swoole
Copied File [/vendor/swooletw/laravel-swoole/config/swoole_http.php] To [/config/swoole_http.php]
Copied File [/vendor/swooletw/laravel-swoole/config/swoole_websocket.php] To [/config/swoole_websocket.php]
Copied File [/vendor/swooletw/laravel-swoole/routes/websocket.php] To [/routes/websocket.php]
Publishing complete.

php artisan swoole:http {start|stop|restart|reload|infos}

php artisan swoole:http start
php artisan swoole:http infos

ab压测结果,开启Swoole与php-fpm相比性能提升3.4785倍

参考:
https://github.com/swooletw/laravel-swoole/wiki