require __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
use Workerman\Lib\Timer;
use Workerman\Connection\AsyncTcpConnection;
$worker = new Worker();
$worker->onWorkerStart = 'connect';
function connect(){
static $count = 0;
echo $count . "\n";
if ($count++ >= 10000) return;
// 建立异步链接
$con = new AsyncTcpConnection('ws://127.0.0.1:8272');
$con->onConnect = function($con) {
// 递归调用connect
connect();
};
$con->onMessage = function($con, $msg) {
$msgInfo = json_decode($msg, true);
if(isset($msgInfo['type']) && $msgInfo['type'] == 'ping'){
$con->send('{"type":"pong"}');
}
echo "r $msg\n";
};
$con->onClose = function($con) {
echo "con close\n";
};
Timer::add(5, function()use($con){
$con->send('{"type":"pong"}');
});
$con->connect();
echo $count, " connections complete\n";
}
Worker::$stdoutFile = '/home/work/im/workerman-chat/start_qa.log';
Worker::runAll();