It's possible to introduce real-time features to PHP applications without deep modifications of the current codebase.
Using WAMP you can build distributed systems out of application components which are loosely coupled and communicate in (soft) real-time.
There is no need to learn a whole new language, with the implications it has.
It also opens the door to write reactive, event-based, distributed architectures and to achieve easier scalability by distributing messages to multiple systems.
3. Agenda
• Concepts and foundations
• Real-time communication patterns
• Implementations
• Examples
4. Real-time
A system is said to be real-time if the total
correctness of an operation depends not only upon
its logical correctness, but also upon the time in
which it is performed
7. Criteria for real-time
• Hard – missing a deadline is a total system failure
• Firm – infrequent deadline misses are tolerable, but
may degrade the system's QoS. Results are NOT
usefulness after its deadline
• Soft – the usefulness of a result degrades after its
deadline, thereby degrading the system’s QoS
9. Soft real-time
Typically used to solve issues of concurrent
access and the need to keep a number of
connected systems up-to-date through
changing situations
10. Soft real-time use cases
• Live audio-video systems
• Users collaboration
• Messaging applications, etc…
• Real-time analytics
• Gaming
• Etc…
11. The road to 500 million
Symfony downloads
https://symfony.com/500million
12. Why adding a soft
real-time feature?
• To improve end-user experience
• Due to insufficient scaling capacity
16. WebSockets
• Full-duplex communication channels over a
single TCP connection
• Currently supported in most major
browsers
• Can be used by any client or server
application
17. HTTP/2
• Major revision of the HTTP
• Replacement for how HTTP is expressed
“on the wire”
• Focus on performance, end-user perceived
latency, network and server resource usage
18. The Mobile Internet
• Inestable connections
• HTTP & TCP slow-start are usually not a
good match for constantly dropped
connections
• Network interface kills battery
• Large responses + periodic polling = bad
26. RPC – Example 3
Communication between micro-services
Auth
Server
login(user)
Analytics Payments
track(user) process(order)
27. Publisher/Subscriber
• A peer subscribe to a topic
• Another peer publish a message about this
topic
• All publishers interested in the topic
receives the message
31. Not to be confused with WAMP:
”Windows + Apache + MySQL + PHP"
32. WAMP
• Open standard WebSocket subprotocol
• Provides two application messaging
patterns in one unified protocol
• Remote Procedure Calls
• Publish & Subscribe
33. WAMP Features
• Enables different technologies, processes,
machines, etc… to communicate with each
other, in soft real-time
34. WAMP Features
• Based on modern Web standards:
WebSocket, JSON and URIs
• Designed with first-class support for
different languages in mind (Polyglot)
35. Unified Application Routing
Routing of events (for PUB/SUB) and routing of
calls (for RPC) in one unified protocol
Caller CalleeDealer
Publisher SubscriberBroker
36. Dealer
• Routes calls from the caller to the callee
and routes back results or errors
• Callers and callee don’t know about each
other
• Applications using RPC benefit from these
loose coupling
Caller CalleeDealer
37. Broker
• Keeps a book of subscriptions
• Forward the events (messages) to all
subscribers
• Publisher are subscribers are loosely
coupled
Publisher SubscriberBroker
38. Unified Protocol
• When you combine a Broker and a Dealer
you get what WAMP calls a Router
Router Broker Dealer= +
39. The Big Picture
WAMP Router
(Dealer + Broker)
BrowserBrowserBrowserBrowser
Mobile
Clients
Services
40. Do we really need
another wheel?
How does WAMMP compare to other technologies
41. Criteria
• Pub/Sub
• RPC
• Routed RPC (not only point-to-point)
• Web native: run natively on the Web (without
tunneling or bridging)
• Cross Language
• Open Standard
44. WAMP Routers
• crossbar.io – Advanced, open-source, full
featured, supported by the creators of
WAMP
• Your own… It’s an open protocol
45. WAMP Ecosystem
• Thruway – library built in PHP that provides
both a client and a router
• Turnpike – router implemented in Go
• wamp.rt – router for NodeJS
• Erwa – router implemented in Erlang
56. Trade-off
• Situation that involves losing one
quality or aspect of something in
return for gaining another quality
or aspect
• It often implies a decision to be
made with full comprehension of
both the upside and downside of
a particular choice
57. Is PHP the right tool
for the job?
There is not simple answer
61. • A big ecosystem of thousands of useful
libraries and components easily installable
thanks to Composer
• Very powerful template engines, ORMs,
etc…
62. • We have implemented very powerful design
patters in PHP coming from Java and other
languages
• We have several thousands of high quality code
running on production
• We have invested multiple hours testing,
refactoring and improving the codebase
67. Upsides
• Possibility to introduce real-time features
without deep modifications in the current
codebase
• No need to learn a whole new language/
stack, with the implications it has
• Loosely coupled systems
68. Upsides cont…
• Opens the door to write reactive, event-
based, distributed architectures
• Scalability is easier to achieve by
distributing messages to multiple systems
70. The Stack
• crossbar.io used as the router (dealer+broker)
• PHP client gathers and publish events
• Silex/Symfony backend serve the data and
contains the biz logic
71. crossbar.io
• Networking platform for distributed and
micro-services applications
• Full implementation of the WAMP protocol
• Feature rich, scalable, robust and secure
• It takes care of the hard parts of messaging
so you can focus on your app's features
72.
73. Tips and Tricks
• WSS
• Deadlines
• Timeouts
• Retries with back-off, etc…
• Idempotency
74. Opinionated
Conclusion
• Understand core concepts and patterns,
technology is volatile
• Question everything: Why?, why not?
• Decide based on several factors: user
experience, scalability, feasibility, developer
experience, maintenance costs/debt, etc…
75. Don’t Stop Here
• gRPC – A high performance, open-source
universal RPC framework from Google
http://www.grpc.io/
• IoT, WoT, etc… – real world objects
connected to the wider internet