您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman查看连接状态
发布时间:2021-11-27 22:33:48编辑:雪饮阅读()
据说需要workerman版本大于3.5.0,而我这里则是4.0.22
首先随便建立一个workerman的随便那个协议的start.php,我这里就以裸tcp为例:
<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
// 创建一个Worker监听2347端口,不使用任何应用层协议
$tcp_worker = new Worker("tcp://0.0.0.0:2347");
// 启动4个进程对外提供服务
$tcp_worker->count = 4;
// 当客户端发来数据时
$tcp_worker->onMessage = function(TcpConnection $connection, $data)
{
// 向客户端发送hello $data
$connection->send('hello ' . $data);
};
// 运行worker
Worker::runAll();
然后没有运行前时候查看连接状态如:
[root@localhost workerman]# php -c /usr/local/php734/lib/php/php.ini start.php connections
Workerman[start.php] connections
Workerman[start.php] not run
然后我运行下:
[root@localhost workerman]# php -c /usr/local/php734/lib/php/php.ini start.php start
Workerman[start.php] start in DEBUG mode
---------------------------------------- WORKERMAN -----------------------------------------
Workerman version:4.0.22 PHP version:7.3.4
----------------------------------------- WORKERS ------------------------------------------
proto user worker listen processes status
tcp root none tcp://0.0.0.0:2347 4 [OK]
--------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
然后我另外开一个会话来再次查看状态:
[root@localhost workerman]# php -c /usr/local/php734/lib/php/php.ini start.php connections
Workerman[start.php] connections
--------------------------------------------------------------------- WORKERMAN CONNECTION STATUS --------------------------------------------------------------------------------
PID Worker CID Trans Protocol ipv4 ipv6 Recv-Q Send-Q Bytes-R Bytes-W Status Local Address Foreign Address
然后用telnet对该tcp服务发消息后:
[root@localhost workerman]# telnet 127.0.0.1 2347
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
chengxiaogua
hello chengxiaogua
我再开第三个会话查看连接状态:
[root@localhost workerman]# php -c /usr/local/php734/lib/php/php.ini start.php connections
Workerman[start.php] connections
--------------------------------------------------------------------- WORKERMAN CONNECTION STATUS --------------------------------------------------------------------------------
PID Worker CID Trans Protocol ipv4 ipv6 Recv-Q Send-Q Bytes-R Bytes-W Status Local Address Foreign Address
7340 none 1 tcp tcp 1 0 0B 0B 14B 20B ESTABLISHED 127.0.0.1:2347 127.0.0.1:49694
关键字词:workerman,连接,状态