← 所有消息

The first layer that lives outside a request

Everything so far happens inside an HTTP request. This is where that stops being the only shape: a WebSocket server that keeps connections open and calls the app when something arrives.

The mechanism is deliberately plain. The server reads the webserver's host configuration, works out which sites have sockets enabled and where each one lives, and then invokes the app the way anyone would from a terminal:

const phpProcess = spawn('/usr/bin/php', [scriptPath, command, ...args])

That one line is why the app side is eleven. There are four lifecycle hooks, auth, connect, receive and close, and an app implements whichever it cares about. No new runtime, no second framework for the socket world, and no application state living in the socket server: it holds connections, the app holds meaning.

Broadcasting goes back the other way over a small local HTTP endpoint, so sending a message to every open screen is a function call from inside an ordinary route.

Two consequences are worth noting now. The CLI entry point becomes load-bearing rather than a convenience, because it is how anything outside a request reaches the app. And keeping the socket layer ignorant of what it carries means it can be replaced, moved or absorbed into something more general without a single app having to change.

See the WebSocket chapter.

我们使用必要的cookie来使该网站正常工作。在您的许可下,我们还使用分析工具来改善网站。