Skip to content

Commit 00cc29f

Browse files
committed
used swoole_table to save vmstat cmd data
1 parent f18a605 commit 00cc29f

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

server/server.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
* 2015-5-5
77
*/
88

9-
const vmstat_path = '/usr/bin/vmstat'; //vmstat命令绝对路径
10-
const vmstat_params = array(1,1000000000); //vmstat 命令参数。格式vmstat part1 part2
11-
const host = "0.0.0.0"; //代表监听全部地址
12-
const port = 8888; //监听端口号
9+
$vmstat_path = '/usr/bin/vmstat'; //vmstat命令绝对路径
10+
$interval = 1; //vmstat 命令参数。指定每个报告之间的时间量
11+
$count = 1000000000; //vmstat 命令参数。决定生成的报告数目和相互间隔的秒数
12+
$host = "0.0.0.0"; //代表监听全部地址
13+
$port = 8888; //监听端口号
1314

1415
/**
1516
* MasterPid命令时格式化输出
@@ -27,7 +28,15 @@
2728
* 创建一个websocket服务器
2829
* 端口8888
2930
*/
30-
$server = new swoole_websocket_server(host, port);
31+
$table = new swoole_table(1024);
32+
$table->column('cmd', swoole_table::TYPE_STRING, 32);
33+
$table->column('interval', swoole_table::TYPE_INT, 2);
34+
$table->column('count', swoole_table::TYPE_STRING, 10);
35+
$table->create();
36+
$table->set('vmstat', array('cmd' => $vmstat_path,'interval' => $interval, 'count' => $count));
37+
38+
$server = new swoole_websocket_server($host, $port);
39+
$server->table = $table; //将table保存在serv对象上
3140

3241
/**
3342
* 创建一个子进程
@@ -77,7 +86,12 @@
7786
* @param swoole_process $worker
7887
*/
7988
function callback_vmstat(swoole_process $worker) {
80-
$worker->exec(vmstat_path, vmstat_params);
89+
global $table;
90+
$vmstat = $table->get('vmstat');
91+
$cmd = $vmstat['cmd'];
92+
$interval = $vmstat['interval'];
93+
$count = $vmstat['count'];
94+
$worker->exec($cmd, array($interval, $count));
8195
}
8296

8397
/**

0 commit comments

Comments
 (0)