PHP 注意:未定義屬性:swoole_http_request::$get
迷茫
迷茫 2017-05-16 13:02:33
0
2
744

為何還會出現如下notice資訊呢?
PHP Notice: Undefined property: swoole_http_request::$get in /var/local/code/swoole/ws_server.php on line 8
PHP Stack trace:
PHP 1. {main}() /var/local//swoole /ws_server.php:0
PHP 2. swoole_http_server->start() /var/local/code/swoole/ws_server.php:23
PHP 3. {closure:/var/local/code/swoole/ws_server.php: 7-10}() /var/local/code/swoole/ws_server.php:23

//创建websocket服务器对象,监听0.0.0.0:9502端口
$ws = new swoole_websocket_server("0.0.0.0", 9502);

//监听WebSocket连接打开事件
$ws->on('open', function ($ws, $request) {
    var_dump($request->fd, $request->get, $request->server);
    $ws->push($request->fd, "hello, welcome\n");
});

//监听WebSocket消息事件
$ws->on('message', function ($ws, $frame) {
    echo "Message: {$frame->data}\n";
    $ws->push($frame->fd, "server: {$frame->data}");
});

//监听WebSocket连接关闭事件
$ws->on('close', function ($ws, $fd) {
    echo "client-{$fd} is closed\n";
});

$ws->start();

js程式碼

var wsServer = 'ws://127.0.0.1:9502';
var websocket = new WebSocket(wsServer);
websocket.onopen = function (evt) {
    console.log("Connected to WebSocket server.");
};

websocket.onclose = function (evt) {
    console.log("Disconnected");
};

websocket.onmessage = function (evt) {
    console.log('Retrieved data from server: ' + evt.data);
};

websocket.onerror = function (evt, e) {
    console.log('Error occured: ' + evt.data);
};
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回覆(2)
洪涛

ws_server.php第六行,request物件沒有get方法

我想大声告诉你

第一個請求是favicon.ico,这里没有get這個屬性的。你把這個請求過濾掉就好了。

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板