我在測試onConnect回調(diào)函數(shù)的時候遇到如下問題.
1.服務(wù)器端代碼:
<?php
use Workerman\Worker;
require_once './Workerman/Autoloader.php';
// 創(chuàng)建一個Worker監(jiān)聽2345端口,使用websocket協(xié)議通訊
$ws_worker = new Worker("websocket://0.0.0.0:2345");
$ws_worker->onConnect = function($connection,$ws_worker){
echo $connection->id."\n";
echo $ws_worker->id."\n";
};
2.成功開啟worker服務(wù);
遇到報錯
PHP Warning: Missing argument 2 for {closure}() in /test.php on line 7
Warning: Missing argument 2 for {closure}() in /test.php on line 7
1
PHP Notice: Undefined variable: ws_worker in /test.php on line 9
Notice: Undefined variable: ws_worker in /test.php on line 9
PHP Notice: Trying to get property of non-object in /test.php on line 9
Notice: Trying to get property of non-object in /test.php on line 9
問題: 在哪定義的onConnect的function()只能傳$connection這一個參數(shù)?手冊上有說明嗎?