❌

Normal view

WebSockets in PHP: what do you think about this approach?

Hello everyone,

I'm curious what PHP developers think about a different way to use WebSockets from scripts.

Imagine requesting (e.g. GET):

new WebSocket("ws://device.local/settings.php?key=value"); 

The server handles the WebSocket upgrade and then executes settings.php as regular PHP script, but with its IO redirected through WebSocket framing:

  • STDIN reads incoming WebSocket data.
  • STDOUT and echo sends data back to the client.

No special WebSocket classes, event loops ,callbacks etc are required in the script. It just runs and communicates through its input/output streams (e.g. via fread() ), the server provides all necessary framing for wth ws:// protocol.

For some context: I am researching an alternative PHP-like language, mainly for embedded devices. Its syntax and execution model are quite close to PHP, and Im thinking if this could be a useful way to handle WebSockets, a feature worth implementing.

Need an experts opinion :)

Does this looks like natural extension of the PHP execution model?

What are your typical ws:// scenarios and how do you handle (in .php code) them ?

Id be interested to hear your opinions, especially practical pros and cons of such approach

Thanks!

submitted by /u/Low_Lawyer_5684 to r/PHP
[link] [comments]
❌