SlideShare a Scribd company logo
Stas Zozulja
stas.z@smart-gamma.com
Real-Time Web applications
with WebSockets
About me
● WEB developer since 2009
● Symfony developer at SmartGamma
since 2013
● https://github.com/stas-zozulja
● https://www.facebook.com/stas.zozulj
a
Real-Time Web applications with Websocket
Real-Time Web applications with Websocket
Agenda
● What is Real-Time Web?
● Transport mechanisms
● Real-Time in PHP (Ratchet)
● && everywhere (Pushpin)
What is Real-Time ?
https://www.leggetter.co.uk/2016/04/22/what-is-realtime.html
● Hard real-time
- missed deadline?
System fault
● Firm real-time
- missed?
Result is zero
● Soft real-time
- missed?
quality degrades
it's all about deadline
and Real-Time Web?
Server pushes a data to Clients when some event
occurs, while Clients does not need to poll a server for
new data.
it's all about Push
https://www.leggetter.co.uk/2016/04/22/what-is-realtime.html
Do I need real-time?
YES! You do!
● Better UX - instant data updates
● Chatting, notification, signaling
● Activity streams
● Data visualization
● User collaboration
Transport mechanisms
● Long polling
● HTTP streaming
● WebSockets
Long polling
Delayed HTTP request. After response (or timeout)
new request is opening by client.
● Uni-directional
● Overhead
(headers in each request)
HTTP Streaming
Request that never ends, response content is
chunked in portions, usually JSON. Only one
direction.
WebSocket protocol
Protocol providing bidirectional communication
channel over a single TCP connection.
WebSocket handshake
Request:
GET /chat HTTP/1.1
Host: ws.example.com:8080/chat
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: T6IDGBEmb...
Connection: Upgrade
Upgrade: websocket
Response:
HTTP/1.1 101 Switching protocols
Connection: Upgrade
Sec-WebSocket-Accept: xTComwY...
Upgrade: websocket
X-Powered-By: Ratchet/0.3.4
ws://
wss://
https://tools.ietf.org/html/rfc6455
http://caniuse.com/#feat=websockets
Support:
● IE 10+
● FF 6+
● Chrome 14+
● iOS 4.2+
● Android 4.4+
● Safari 5+
Our context
● Live streaming app
● REST API for mobile clients (iOS, Android)
● WEB part
● Build Real-time counter of viewers
or
Ratchet - WebSockets for PHP
http://socketo.me/
Built on top of ReactPHP
Components:
● I/O (socket transport) – IOServer
● HTTP Protocol handler – HTTPServer
● WebSocket Protocol Handler – WSServer
● SessionProvider – Symfony Session
● WAMP Protocol Handler – WampServer
+
● Your Application
MessageComponentInterface implementation
http://reactphp.org/
& Step 1. Implement MessageComponentInterface
& Step 2. onMessage()
& Step 3. Write Console command that runs a server
& Next steps. WAMP Subprotocol.
● WAMP – Web Application Messaging
Protocol.
● RPC and Pub/Sub patterns
● Autobahn client libraries
http://wamp-proto.org/
http://autobahn.ws/
&
Cons
● Horizontally scaling is hard
need to share a Connections between nodes
● One exception can stop whole server
Use supervisord, try...catch, test Your code
Pros
● Its PHP!
● Easy to implement and use existing code
https://www.leggetter.co.uk/real-time-web-technologies-guide/
j.mp/realtime-tech-guide
https://fanout.io/
Pushpin
a reverse proxy for the real-time Web
http://pushpin.org/
● Pub/Sub
● Long polling, HTTP Streaming or WebSockets
● Works with any backend
● Your API can be real-time with HTTP streaming
● WebSocket over HTTP – what? :)
https://fanout.io/
Pushpin installation
Debian, Ubuntu:
sudo apt-get install pushpin
sudo service pushpin start
http://pushpin.org/docs/#install
MacOS X:
brew install pushpin
pushpin
Pushpin configuration
routes config file:
* localhost:80,over_http
● route all connections from Pushpin to
your backend
● over_http option to enable
WebSocket-over-HTTP protocol
https://github.com/fanout/pushpin/wiki
https://github.com/fanout/pushpin/blob/master/docs/websocket-over-http.md
WebSocket-over-HTTP (GRIP protocol)
Pushpin encodes WebSocket events into a regular HTTP
requests and passes them to your backend.
Events are:
OPEN – opening WebSocket connection message
TEXT, BINARY – content messages
PING, PONG – ping/pong messages
CLOSE - Close message with 16-bit close code
DISCONNECT - Indicates connection closed uncleanly
1. From client to Pushpin (port 7999):
GET /chat HTTP/1.1
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: T6IDGBEmb...
Connection: Upgrade
Upgrade: websocket
2. From Pushpin to backend:
POST /chat HTTP/1.1
Sec-WebSocket-Extensions: grip
Content-Type:
application/websocket-events
Accept:
application/websocket-events
OPENrn
2. Response:
HTTP/1.1 200 OK
Sec-WebSocket-Extensions: grip
Content-Type:
application/websocket-events
OPENrn
WebSocket over HTTP connection flow
3. Form Pushpin to client:
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBi...
Sec-WebSocket-Extensions: grip
1. From client to Pushpin (port 7999):
//sending message
WebSocket.send(“Hello there! I’m client!”);
2. From Pushpin to backend:
POST /chat HTTP/1.1
Sec-WebSocket-Extensions: grip
Content-Type:
application/websocket-events
Accept:
application/websocket-events
TEXT 18rn
Hello there! I’m client!
2. Response:
HTTP/1.1 200 OK
Sec-WebSocket-Extensions: grip
Content-Type:
application/websocket-events
TEXT 12rn
Hello! I’m server!
TEXT 2Frn
c:{"type": "subscribe", "channel":
"mychannel"}rn
WebSocket over HTTP message flow
3. On client:
//receiving message
WebSocket.onMesssage(event) …
//event.data is “Hello! I’m server!”
PublishSubscribe. Control messages.
Formatted as a JSON object following the c: prefix. The object has a type
field that indicates the type of control message.
● subscribe: Subscribe connection to the channel specified by the
channel field.
● unsubscribe: Unsubscribe connection from the channel specified by
the channel field.
● detach: Terminate the session between Pushpin and the origin server,
but retain the connection between the client and
http://pushpin.org/docs/#websockets
Examples:
c:{"type": "subscribe", "channel": "test"}
c:{"type": "unsubscribe", "channel": "test"}
Prefix c: is configurable
Publish data to a channel
POST request to a Pushpin’s internal publish port
(5561 by default)
curl -d
'{"items": [
{ "channel": "test",
"formats": {
"ws-message": {
"content": "hello
theren"
}
}
}
]
}' http://localhost:5561/publish/
1. From client to Pushpin:
GET /chat HTTP/1.1
Sec-WebSocket-Version: 13
Sec-WebSocket-Key:
T6IDGBEmb...
Connection: Upgrade
Upgrade: websocket
2. Request:
POST /chat HTTP/1.1
Sec-WebSocket-Extensions: grip
Content-Type:
application/websocket-
events
Accept:
application/websocket-
events
OPENrn
2. Response:
HTTP/1.1 200 OK
Sec-WebSocket-Extensions: grip
Content-Type:
application/websocket-
events
OPENrn
So, all we need is to handle Requests from Pushpin
in our application. A GOOD job for Symfony, isn't it?
3. Form Pushpin to client:
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBi...
Sec-WebSocket-Extensions: grip
PHP Library to work with Pushpin on server side
composer require fanout/gripcontrol
https://github.com/fanout/php-
gripcontrol
Publishing from PHP
https://github.com/fanout/php-
gripcontrol
Symfony Bundle
https://github.com/smart-gamma/pushpin-bundle
&
Features
● Works with WebSocket-over-HTTP Requests from
Pushpin
● TEXT events deserialization into DTOs (events)
specified by your configuration
● Handling WebSocketEvent with your specific
handler
● Pushpin helpers to publishing to a channel,
subscribing, detaching etc.
Live Demo&
http://ws-chat.smart-gamma.com
https://github.com/smart-gamma/simple-chat-
demo
Symfony Bundle
$ composer require gamma/pushpin-bundle
# config.yml
gamma_pushpin:
proxy:
control_uri: 'http://localhost:5561/'
web_socket:
json_events:
base_namespace: 'DomainWebsocketEvents'
mappings:
chatMessage:
class: 'ChatChatMessage'
chatRoomEnter:
class: 'ChatChatRoomEnter'
chatRoomLeave:
class: 'ChatChatRoomLeave'
&
Simple DTO object to hold event data&
Implement handler service
for your event
&
Controller to handle requests from
Pushpin
&
Test with wscat utility&
&
http://blog.fanout.io/2013/10/30/pushing-to-100000-api-clients-simultaneously/
Pros
● It’s still PHP!
● No need to run
long lived processes at backend
● With HTTP Streaming You can
make a real-time API
● Horizontally scalable
Cons
● If you have multi nodes,
pushes should be sent to all
Pushpin instances
● More HTTP requests to your
application
● Push can be sent only to a
channel
Load testing with thor utility
Thank You!

More Related Content

PPTX
Smart Gamma - Real-Time Web applications with PHP and Websocket.
PDF
Realtime Streaming using Autobahn Websockets
PDF
Real-Time Web Apps & .NET - What are your options?
PDF
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
PDF
A few words about WAMP
PDF
Building Realtime Apps with Ember.js and WebSockets
PPTX
Ruby in the Browser - RubyConf 2011
PPTX
Ruby C10K: High Performance Networking - RubyKaigi '09
Smart Gamma - Real-Time Web applications with PHP and Websocket.
Realtime Streaming using Autobahn Websockets
Real-Time Web Apps & .NET - What are your options?
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
A few words about WAMP
Building Realtime Apps with Ember.js and WebSockets
Ruby in the Browser - RubyConf 2011
Ruby C10K: High Performance Networking - RubyKaigi '09

What's hot (20)

KEY
Movable Type 5.2 Overview at MTDDC 2012
PPTX
Real-time Ruby for the Real-time Web
PDF
44CON London 2015 - Going AUTH the Rails on a Crazy Train
PDF
Communication in Python and the C10k problem
PPT
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
PPTX
0-60 with Goliath: Building High Performance Ruby Web-Services
PDF
LCA2014 - Introduction to Go
ODP
Perl comet
PPTX
Ruby Proxies for Scale, Performance, and Monitoring
PDF
Ugo Cei Presentation
PPT
2 Asp Dot Net Ajax Extensions
PDF
The MetaCPAN VM for Dummies Part One (Installation)
PPT
AppengineJS
PDF
ZendCon 2015 - DevOps for Small Teams
PDF
Web Leaps Forward
PDF
Profiling PHP with Xdebug / Webgrind
KEY
Speedy TDD with Rails
PPTX
No Callbacks, No Threads - RailsConf 2010
PDF
Crash course to the Apache Camel
PDF
Camel and JBoss
Movable Type 5.2 Overview at MTDDC 2012
Real-time Ruby for the Real-time Web
44CON London 2015 - Going AUTH the Rails on a Crazy Train
Communication in Python and the C10k problem
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
0-60 with Goliath: Building High Performance Ruby Web-Services
LCA2014 - Introduction to Go
Perl comet
Ruby Proxies for Scale, Performance, and Monitoring
Ugo Cei Presentation
2 Asp Dot Net Ajax Extensions
The MetaCPAN VM for Dummies Part One (Installation)
AppengineJS
ZendCon 2015 - DevOps for Small Teams
Web Leaps Forward
Profiling PHP with Xdebug / Webgrind
Speedy TDD with Rails
No Callbacks, No Threads - RailsConf 2010
Crash course to the Apache Camel
Camel and JBoss
Ad

Similar to Real-Time Web applications with WebSockets (20)

PDF
DevCon 5 (July 2013) - WebSockets
PDF
Http Push
PDF
Building real time applications with Symfony2
PDF
Adding Real-time Features to PHP Applications
PPTX
Training Webinar: Enterprise application performance with server push technol...
KEY
Pushing the web — WebSockets
PDF
Real time web apps
PPTX
WebSocket protocol
PDF
Building interactivity with websockets
PDF
Gripshort
PPT
PPTX
Programming WebSockets with Glassfish and Grizzly
PPTX
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
PDF
HTML5 WebSockets
PPTX
WebSockets-Revolutionizing-Real-Time-Communication.pptx
PDF
Building Next Generation Real-Time Web Applications using Websockets
PPTX
Language agnostic technologies introduced in pi web-agent 0.4rc2
PPT
Camelone-2012 HTML5 WebSocket ActiveMQ/Camel
PDF
WebSocket
PPTX
Real time websites and mobile apps with SignalR
DevCon 5 (July 2013) - WebSockets
Http Push
Building real time applications with Symfony2
Adding Real-time Features to PHP Applications
Training Webinar: Enterprise application performance with server push technol...
Pushing the web — WebSockets
Real time web apps
WebSocket protocol
Building interactivity with websockets
Gripshort
Programming WebSockets with Glassfish and Grizzly
SenchaCon 2016: How to Give your Sencha App Real-time Web Performance - James...
HTML5 WebSockets
WebSockets-Revolutionizing-Real-Time-Communication.pptx
Building Next Generation Real-Time Web Applications using Websockets
Language agnostic technologies introduced in pi web-agent 0.4rc2
Camelone-2012 HTML5 WebSocket ActiveMQ/Camel
WebSocket
Real time websites and mobile apps with SignalR
Ad

Recently uploaded (20)

PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
System and Network Administration Chapter 2
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
ai tools demonstartion for schools and inter college
PDF
medical staffing services at VALiNTRY
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Digital Strategies for Manufacturing Companies
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
top salesforce developer skills in 2025.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Reimagine Home Health with the Power of Agentic AI​
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
System and Network Administration Chapter 2
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
2025 Textile ERP Trends: SAP, Odoo & Oracle
ai tools demonstartion for schools and inter college
medical staffing services at VALiNTRY
How to Migrate SBCGlobal Email to Yahoo Easily
Design an Analysis of Algorithms II-SECS-1021-03
Navsoft: AI-Powered Business Solutions & Custom Software Development
VVF-Customer-Presentation2025-Ver1.9.pptx
Digital Strategies for Manufacturing Companies
Internet Downloader Manager (IDM) Crack 6.42 Build 41
top salesforce developer skills in 2025.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Odoo Companies in India – Driving Business Transformation.pdf
PTS Company Brochure 2025 (1).pdf.......
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)

Real-Time Web applications with WebSockets

  • 2. About me ● WEB developer since 2009 ● Symfony developer at SmartGamma since 2013 ● https://github.com/stas-zozulja ● https://www.facebook.com/stas.zozulj a Real-Time Web applications with Websocket
  • 3. Real-Time Web applications with Websocket Agenda ● What is Real-Time Web? ● Transport mechanisms ● Real-Time in PHP (Ratchet) ● && everywhere (Pushpin)
  • 4. What is Real-Time ? https://www.leggetter.co.uk/2016/04/22/what-is-realtime.html ● Hard real-time - missed deadline? System fault ● Firm real-time - missed? Result is zero ● Soft real-time - missed? quality degrades it's all about deadline
  • 5. and Real-Time Web? Server pushes a data to Clients when some event occurs, while Clients does not need to poll a server for new data. it's all about Push https://www.leggetter.co.uk/2016/04/22/what-is-realtime.html
  • 6. Do I need real-time? YES! You do! ● Better UX - instant data updates ● Chatting, notification, signaling ● Activity streams ● Data visualization ● User collaboration
  • 7. Transport mechanisms ● Long polling ● HTTP streaming ● WebSockets
  • 8. Long polling Delayed HTTP request. After response (or timeout) new request is opening by client. ● Uni-directional ● Overhead (headers in each request)
  • 9. HTTP Streaming Request that never ends, response content is chunked in portions, usually JSON. Only one direction.
  • 10. WebSocket protocol Protocol providing bidirectional communication channel over a single TCP connection.
  • 11. WebSocket handshake Request: GET /chat HTTP/1.1 Host: ws.example.com:8080/chat Sec-WebSocket-Version: 13 Sec-WebSocket-Key: T6IDGBEmb... Connection: Upgrade Upgrade: websocket Response: HTTP/1.1 101 Switching protocols Connection: Upgrade Sec-WebSocket-Accept: xTComwY... Upgrade: websocket X-Powered-By: Ratchet/0.3.4 ws:// wss:// https://tools.ietf.org/html/rfc6455 http://caniuse.com/#feat=websockets Support: ● IE 10+ ● FF 6+ ● Chrome 14+ ● iOS 4.2+ ● Android 4.4+ ● Safari 5+
  • 12. Our context ● Live streaming app ● REST API for mobile clients (iOS, Android) ● WEB part ● Build Real-time counter of viewers or
  • 13. Ratchet - WebSockets for PHP http://socketo.me/ Built on top of ReactPHP Components: ● I/O (socket transport) – IOServer ● HTTP Protocol handler – HTTPServer ● WebSocket Protocol Handler – WSServer ● SessionProvider – Symfony Session ● WAMP Protocol Handler – WampServer + ● Your Application MessageComponentInterface implementation http://reactphp.org/
  • 14. & Step 1. Implement MessageComponentInterface
  • 15. & Step 2. onMessage()
  • 16. & Step 3. Write Console command that runs a server
  • 17. & Next steps. WAMP Subprotocol. ● WAMP – Web Application Messaging Protocol. ● RPC and Pub/Sub patterns ● Autobahn client libraries http://wamp-proto.org/ http://autobahn.ws/
  • 18. & Cons ● Horizontally scaling is hard need to share a Connections between nodes ● One exception can stop whole server Use supervisord, try...catch, test Your code Pros ● Its PHP! ● Easy to implement and use existing code
  • 21. Pushpin a reverse proxy for the real-time Web http://pushpin.org/ ● Pub/Sub ● Long polling, HTTP Streaming or WebSockets ● Works with any backend ● Your API can be real-time with HTTP streaming ● WebSocket over HTTP – what? :) https://fanout.io/
  • 22. Pushpin installation Debian, Ubuntu: sudo apt-get install pushpin sudo service pushpin start http://pushpin.org/docs/#install MacOS X: brew install pushpin pushpin
  • 23. Pushpin configuration routes config file: * localhost:80,over_http ● route all connections from Pushpin to your backend ● over_http option to enable WebSocket-over-HTTP protocol https://github.com/fanout/pushpin/wiki https://github.com/fanout/pushpin/blob/master/docs/websocket-over-http.md
  • 24. WebSocket-over-HTTP (GRIP protocol) Pushpin encodes WebSocket events into a regular HTTP requests and passes them to your backend. Events are: OPEN – opening WebSocket connection message TEXT, BINARY – content messages PING, PONG – ping/pong messages CLOSE - Close message with 16-bit close code DISCONNECT - Indicates connection closed uncleanly
  • 25. 1. From client to Pushpin (port 7999): GET /chat HTTP/1.1 Sec-WebSocket-Version: 13 Sec-WebSocket-Key: T6IDGBEmb... Connection: Upgrade Upgrade: websocket 2. From Pushpin to backend: POST /chat HTTP/1.1 Sec-WebSocket-Extensions: grip Content-Type: application/websocket-events Accept: application/websocket-events OPENrn 2. Response: HTTP/1.1 200 OK Sec-WebSocket-Extensions: grip Content-Type: application/websocket-events OPENrn WebSocket over HTTP connection flow 3. Form Pushpin to client: HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: s3pPLMBi... Sec-WebSocket-Extensions: grip
  • 26. 1. From client to Pushpin (port 7999): //sending message WebSocket.send(“Hello there! I’m client!”); 2. From Pushpin to backend: POST /chat HTTP/1.1 Sec-WebSocket-Extensions: grip Content-Type: application/websocket-events Accept: application/websocket-events TEXT 18rn Hello there! I’m client! 2. Response: HTTP/1.1 200 OK Sec-WebSocket-Extensions: grip Content-Type: application/websocket-events TEXT 12rn Hello! I’m server! TEXT 2Frn c:{"type": "subscribe", "channel": "mychannel"}rn WebSocket over HTTP message flow 3. On client: //receiving message WebSocket.onMesssage(event) … //event.data is “Hello! I’m server!”
  • 27. PublishSubscribe. Control messages. Formatted as a JSON object following the c: prefix. The object has a type field that indicates the type of control message. ● subscribe: Subscribe connection to the channel specified by the channel field. ● unsubscribe: Unsubscribe connection from the channel specified by the channel field. ● detach: Terminate the session between Pushpin and the origin server, but retain the connection between the client and http://pushpin.org/docs/#websockets Examples: c:{"type": "subscribe", "channel": "test"} c:{"type": "unsubscribe", "channel": "test"} Prefix c: is configurable
  • 28. Publish data to a channel POST request to a Pushpin’s internal publish port (5561 by default) curl -d '{"items": [ { "channel": "test", "formats": { "ws-message": { "content": "hello theren" } } } ] }' http://localhost:5561/publish/
  • 29. 1. From client to Pushpin: GET /chat HTTP/1.1 Sec-WebSocket-Version: 13 Sec-WebSocket-Key: T6IDGBEmb... Connection: Upgrade Upgrade: websocket 2. Request: POST /chat HTTP/1.1 Sec-WebSocket-Extensions: grip Content-Type: application/websocket- events Accept: application/websocket- events OPENrn 2. Response: HTTP/1.1 200 OK Sec-WebSocket-Extensions: grip Content-Type: application/websocket- events OPENrn So, all we need is to handle Requests from Pushpin in our application. A GOOD job for Symfony, isn't it? 3. Form Pushpin to client: HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: s3pPLMBi... Sec-WebSocket-Extensions: grip
  • 30. PHP Library to work with Pushpin on server side composer require fanout/gripcontrol https://github.com/fanout/php- gripcontrol
  • 32. Symfony Bundle https://github.com/smart-gamma/pushpin-bundle & Features ● Works with WebSocket-over-HTTP Requests from Pushpin ● TEXT events deserialization into DTOs (events) specified by your configuration ● Handling WebSocketEvent with your specific handler ● Pushpin helpers to publishing to a channel, subscribing, detaching etc.
  • 34. Symfony Bundle $ composer require gamma/pushpin-bundle # config.yml gamma_pushpin: proxy: control_uri: 'http://localhost:5561/' web_socket: json_events: base_namespace: 'DomainWebsocketEvents' mappings: chatMessage: class: 'ChatChatMessage' chatRoomEnter: class: 'ChatChatRoomEnter' chatRoomLeave: class: 'ChatChatRoomLeave' &
  • 35. Simple DTO object to hold event data&
  • 37. Controller to handle requests from Pushpin &
  • 38. Test with wscat utility&
  • 39. & http://blog.fanout.io/2013/10/30/pushing-to-100000-api-clients-simultaneously/ Pros ● It’s still PHP! ● No need to run long lived processes at backend ● With HTTP Streaming You can make a real-time API ● Horizontally scalable Cons ● If you have multi nodes, pushes should be sent to all Pushpin instances ● More HTTP requests to your application ● Push can be sent only to a channel
  • 40. Load testing with thor utility