Implementation of the onError() handler
programarivm opened this issue · 1 comments
programarivm commented
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:
-
Why is the WebSocket example ignoring this one handler?
-
Is it necessary to close the connection when an error occurs?
-
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,
walkor commented
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.