Linux下载安装:
git clone https://github.com/swoole/swoole-src.git && \
cd swoole-src && \
phpize && \
./configure && \
make && make install
或者
pecl install swoole
然后再php.in中添加
extension=swoole.so
重启php
service php-fpm restart
查看phpinfo是否有了swoole服务
假设以nginx为web服务器:
创建WebSocket服务器
<?php
$server = new swoole_websocket_server("0.0.0.0", 9501);
$server->on('open', function (swoole_websocket_server $server, $request) {
file_put_contents('a.log',$request->fd."\r\n",FILE_APPEND);
echo "server: handshake success with fd{$