mirror of
https://github.com/Qbix/webserver.git
synced 2026-07-22 07:57:23 +02:00
Added socket->disconnect() method for use by child processes
This commit is contained in:
@@ -766,6 +766,7 @@ function chat_message(&$params, &$result) {
|
|||||||
| `$socket->broadcastAll($data)` | Send to ALL connected clients |
|
| `$socket->broadcastAll($data)` | Send to ALL connected clients |
|
||||||
| `$socket->join($room, $data)` | Join a room, forwarding `$data` to the room's join handler |
|
| `$socket->join($room, $data)` | Join a room, forwarding `$data` to the room's join handler |
|
||||||
| `$socket->leave($room, $data)` | Leave a room, forwarding `$data` to the room's leave handler |
|
| `$socket->leave($room, $data)` | Leave a room, forwarding `$data` to the room's leave handler |
|
||||||
|
| `$socket->disconnect()` | Close this connection |
|
||||||
| `$socket->anyMethod($data)` | **RPC** — calls a method on the client, blocks until response (5s timeout) |
|
| `$socket->anyMethod($data)` | **RPC** — calls a method on the client, blocks until response (5s timeout) |
|
||||||
|
|
||||||
**Room handlers** get `$room` — a `Q_Room` instance:
|
**Room handlers** get `$room` — a `Q_Room` instance:
|
||||||
@@ -2170,7 +2171,17 @@ Changes are logged to stderr:
|
|||||||
14:32:09 hot-reload: restarting server...
|
14:32:09 hot-reload: restarting server...
|
||||||
```
|
```
|
||||||
|
|
||||||
Polls every 2 seconds. Use in development, not production.
|
Polls every 2 seconds. Recommended for development.
|
||||||
|
|
||||||
|
Even without `--hotreload`, handler changes take effect naturally: HTTP
|
||||||
|
requests fork fresh and load handlers on demand, so the next request gets the
|
||||||
|
new file. WebSocket connections and rooms keep the old code for their lifetime
|
||||||
|
— new connections pick up the change. A natural rolling deploy with no
|
||||||
|
interruption. The `--hotreload` flag adds automatic restart for class and
|
||||||
|
config changes, which are preloaded in the parent process.
|
||||||
|
|
||||||
|
If `Q.handlers.preload` is `true` (production mode), handlers are also loaded
|
||||||
|
in the parent — use `--reload` to pick up handler changes in that case.
|
||||||
|
|
||||||
### Scheduler
|
### Scheduler
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -595,6 +595,9 @@ class Q_Socket
|
|||||||
/** Leave a room, optionally forwarding data to the room's leave handler */
|
/** Leave a room, optionally forwarding data to the room's leave handler */
|
||||||
function leave($room, $data = array()) { self::_cmd(array('cmd' => 'leave', 'socketId' => $this->id, 'room' => $room, 'data' => $data)); }
|
function leave($room, $data = array()) { self::_cmd(array('cmd' => 'leave', 'socketId' => $this->id, 'room' => $room, 'data' => $data)); }
|
||||||
|
|
||||||
|
/** Disconnect this client */
|
||||||
|
function disconnect() { self::_cmd(array('cmd' => 'disconnect', 'socketId' => $this->id)); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call a method on the remote client. Blocks until the client responds.
|
* Call a method on the remote client. Blocks until the client responds.
|
||||||
* The client must have registered a handler via qs.handle('methodName', fn).
|
* The client must have registered a handler via qs.handle('methodName', fn).
|
||||||
|
|||||||
@@ -874,6 +874,9 @@ class Q_WebSocket
|
|||||||
case 'ack':
|
case 'ack':
|
||||||
self::sendAck($cmd['socketId'], $cmd['ackId'], $cmd['data']);
|
self::sendAck($cmd['socketId'], $cmd['ackId'], $cmd['data']);
|
||||||
break;
|
break;
|
||||||
|
case 'disconnect':
|
||||||
|
self::disconnect($cmd['socketId']);
|
||||||
|
break;
|
||||||
case 'rpc':
|
case 'rpc':
|
||||||
self::handleRpc($cmd);
|
self::handleRpc($cmd);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user