The PHP example
A whole shop in plain PHP, in the package examples/php: sign in as Ann (support), Ben (a customer) or Cara (the warehouse), each in a browser of their own, and try everything this guide covers.

| On the page | What makes it |
|---|---|
| The order of Ben follows as Ann moves it on, and Ben alone gets a notice | the order:{id} room, sent to by POST /orders/1042/status with except, and toUser (sending) |
| The chat of Ann and Ben, with typing, reactions and read ticks | <wordplus-chat> on the chat:{a}:{b} room, which lets pages send them. The server keeps the conversation from the webhook and gives it back from GET /chat/messages (keeping the conversation). The name and picture of the other side above it from the directory |
| Who is in the shop, with a call button for each | <wordplus-online> on the shop presence room, the name and role of each member |
| The daily meeting | <wordplus-room>, a group call |
| The order timeline, and what the cloud carried of it | the order room history. GET /orders/1042/wire seals the update as the server sends it, with the room key (encryption) |
| How many are looking at the mugs | the product:{id} room, public and counted |
| The webhooks the server got | $realtime->on('*'), which sends each on to the shop webhooks room (webhooks) |
Try it online at php.docs.wordplus.cloud: this example as a demo, where every visitor gets a shop of their own for a day, and its links open Ben and Cara in windows of their own. Its calls end after 10 minutes and its meetings after 15 (limits in the demo part, which the page keeps to).
Run it
cd examples/php
cp .env.example .env # the key and secret of your app, with http://localhost:8000 among its addresses, and a local key
composer install # wordplus/realtime-php
npm install # bundles the page, and copies the worker, the room client and the components into public/
php -S localhost:8000 -t public public/index.php
Open it in two browsers (or a private window), sign in as Ann in one and Ben in the other, and move the order on, chat, and call. It takes wordplus/realtime-php from this repository. In your own app, composer require wordplus/realtime-php.
Its files
| File | |
|---|---|
src/app.php | the realtime SDK with the rooms and calls it declares and its webhooks, the shop people, and its shops in a JSON file, by number |
src/demo.php | the demo part alone (WORDPLUS_DEMO=1): a shop for each visitor, its windows, and the frame around the page |
public/index.php | the front controller: the browser routes and the webhook, signing in, the order routes, and the page |
templates/page.php | the page, with the user config() and the shop data as two JSON blocks |
shop/shop.js | the page script: connect(), the order, the product, the chat, who is in the shop, the webhooks, the meeting and the call screen. The same file runs the shop in every example |
Behind Apache or nginx, point the web root at public/ and send every request that is not a file to index.php (deploying).