有没有会监听本地变量改变,然后发送消息给服务器/客户端,目前tcp socket用的workerman连成功了,但只能连接上的时候发一次消息
<?php
session_start();
use GlobalData\Client;
require __DIR__ .'\GlobalData-master\GlobalData-master\src\Client.php';
$global = new GlobalData\Client('127.0.0.1:2207');
?>
<?php
//session_start();
use Workerman\Worker;
use Workerman\Connection\AsyncTcpConnection;
//use GlobalData\Client;
require __DIR__ . '\vendor\autoload.php';
//require __DIR__ .'\GlobalData-master\GlobalData-master\src\Client.php';
//echo $global->send;
//tcp客户端
$worker = new Worker();
$worker->onWorkerStart = function($worker){
// $con = new AsyncTcpConnection('tcp://192.168.2.16:26214');
$con = new AsyncTcpConnection('tcp://127.0.0.1:8889');
//$global = new GlobalData\Client('127.0.0.1:2207');
$con->onConnect = function(AsyncTcpConnection $con) {
$con->send($global->send);
};
$con->onMessage = function(AsyncTcpConnection $con, $data) {
echo $data;
};
$con->connect();
};
Worker::runAll();
?>
目前想的定时器和Event,不知道是否适用。
模拟一下使用场景