Super simple PHP WebSocket example

V. K.
1 min readSep 21, 2017

--

Here you will find most super simple PHP WebSocket example.
2 tiny files, few seconds — and you have working WebSocket example!

The main purpose of this article — show that WebSocket in PHP it isn’t something big, ugly, awkward, sophisticated and unreal…

Prerequisites

Create file websockets.html with next content:

Create file websockets.php with next content:

Engagement

Start in shell WebSocket server: php -q websockets.php.
Start in shell WebSocket client: php -S 0.0.0.0:8000 websockets.html please use separated tab in terminal.

Test

Open in browser URL: http://0.0.0.0:8000/ you will see current timestamp which will continuously updating! Hence, it works!

Conclusion

This is just super simple PHP WebSocket example.
Yes, it isn’t real world example, but it is as simple as possible sample
which you can use as starting basis for your next experiments!

--

--