PHP code example of xiongchao / swoole-monitor

1. Go to this page and download the library: Download xiongchao/swoole-monitor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xiongchao / swoole-monitor example snippets


    ;swoole server config set
    [server]
    host = 0.0.0.0   ;监听的网络地址
    port = 9503      ;监听的端口
    process_title=monitor_master  ;自定义设置进程名称,可为空 windows&macos下不支持
    ;swoole执行脚本文件名 位于app/Serve/scripts 目录下
    script_path=Swoole.php
    
    [server2]
    host = 0.0.0.0
    port = 9504
    process_title=monitor_master2
    script_path=Swoole.php

 bash
tcp:serve为自定义的命令名称,--daemon为可选参数(在 start、restart和reload的时候可加),默认为false,设置为true的时候进程以守护进程模式启动
php artisan.php tcp:serve start --daemon=true
测试结果如下:
[server] 服务启动成功,进程ID: 21836
[server2] 服务启动成功,进程ID: 21845

php artisan.php tcp:serve stop
测试结果如下:
[server]服务进程ID:21836,已停止
[server2]服务进程ID:21845,已停止

...

 bash
tcp:single为自定义的命令名称,--option为并填参数,可为start|stop|restart|reload|status,--serve为并填参数,为配置文件swoole.ini中的section值,--daemon为可选参数(在 start、restart和reload的时候可加),默认为false,设置为true的时候进程以守护进程模式启动
php artisan.php tcp:single --option=start --serve=server --daemon=true
测试结果如下:
[server] 服务启动成功,进程ID: 21836

php artisan.php tcp:single --option=stop --serve=server 
测试结果如下:
[server]服务进程ID:21836,已停止

...

 bash
php artisan.php tcp:serve status

php artisan.php tcp:single --option=status --serve=server 

 bash

模拟接收推送数据
php App/Client/PushClientTest.php
模拟上报数据(本例将上报数据推送给接收推送的所有客户端)
php App/Client/ReportClientTest.php