在process目录下创建Websocket的进程类,启动服务时 提示进程类不存在
<?php
namespace process;
use Workerman\Connection\TcpConnection;
class WebSockets
{
public function onConnect(TcpConnection $connection)
{
echo "onConnect\n";
}
public function onWebSocketConnect(TcpConnection $connection, $http_buffer)
{
echo "onWebSocketConnect\n";
}
public function onMessage(TcpConnection $connection, $data)
{
$connection->send($data);
}
public function onClose(TcpConnection $connection)
{
echo "onClose\n";
}
}
'Websockets' => [
// 进程类
'handler' => process\Websockets::class,
'listen' => 'websocket://0.0.0.0:8989',
// 进程数 (可选,默认1)
'count' => 1,
// 当前进程是否支持reload (可选,默认true)
'reloadable' => true,
],
php start.php start
操作系统:centos6.0
PHP:>=7.4
workerman:^1.5
由于Linux系统中大小写要求比较严格,一个字符写错可能就导致不能使用