walkor / workerman

An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols.

Home Page:http://www.workerman.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implementation of the onError() handler

programarivm opened this issue · comments

Hello, I just noticed that the $ws_worker->onError() handler is missing in the WebSocket server example and was wondering if the following one would be okay.

// ...

        $this->worker->onError = function ($conn, $code, $msg) {
            $conn->close();

            echo "error $code $msg\n";
        };

// ...

Questions:

  1. Why is the WebSocket example ignoring this one handler?

  2. Is it necessary to close the connection when an error occurs?

  3. Or should it perhaps be as per the onError documentation?

// ...

        $this->worker->onError = function ($conn, $code, $msg) {
            echo "error $code $msg\n";
        };

// ...

Thanks for the help,

Workerman has many callback methods, and it's not possible to list all callbacks in every example. More detailed usage should be referred to the manual. https://manual.workerman.net/doc/en/worker/on-error.html
The manual has listed all the situations where errors occur, and whether to close the connection depends on the business logic.