SlideShare a Scribd company logo
Realtime Communication Techniques with PHP Scott Mattocks & Chris Lewis, OnForce, Inc.
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Introductions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Overview ,[object Object],[object Object]
Overview ,[object Object],[object Object],[object Object]
Problems with delivery ,[object Object],[object Object],[object Object],[object Object],[object Object]
Problems with delivery ,[object Object],[object Object],[object Object],Client Server New Data New Data Black out
Problems with delivery ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Problems with delivery ,[object Object],[object Object],[object Object],[object Object]
Solutions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Solutions @gnomeboy want to come over for some cookies? @gnomegirl hellz yeah! ,[object Object]
Solutions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Refresh ,[object Object],[object Object],[object Object],[object Object],[object Object]
Refresh database web server web server
Refresh ,[object Object],[object Object],[object Object],[object Object],[object Object]
Refresh ,[object Object],[object Object],[object Object],[object Object]
Refresh ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Short Polling ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Short Polling database web server web server
Short Polling ,[object Object],[object Object],[object Object],[object Object],[object Object]
Short Polling function   poll_server () { new  Ajax. Request ( this .urlPolling, { method:  'post' , parameters: data, onSuccess:  this .successHandler, onFailure:  this .handleFailure, onException:  this .handleException }); } setInterval ( 'poll_server()' ,  5000 );
Short Polling function   successHandler (trans, messages_div) { if  (trans.responseText) { var  json = trans.responseText. evalJSON (); if  (json.message) { var  msg = json.message +  '<br />' ; $(messages_div). insert (msg); } } }
Short Polling function   successHandler (trans, messages_div) { if  (trans.responseText) { var  json = trans.responseText. evalJSON (); if  (json.message) { var  msg = json.message +  '<br />' ; $(messages_div). insert (msg); } } }
Short Polling ,[object Object],[object Object],[object Object],[object Object]
Short Polling ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Long Polling - 1 server ,[object Object],[object Object],[object Object],[object Object],[object Object]
Long Polling – 1 server database web server web server
Long Polling – 1 server ,[object Object],[object Object],[object Object],[object Object],[object Object]
Long Polling – 1 server ,[object Object],[object Object],[object Object],[object Object]
Long Polling – 1 server function   poll_server () { new  Ajax. Request ( this .urlPolling, { method:  'post' , parameters: data, onSuccess:  this .successHandler, onFailure:  this .handleFailure, onException:  this .handleException }); } document. observe ( 'dom:loaded' , poll_server);
Long Polling – 1 server function   successHandler (trans, messages_div) { if  (trans.responseText) { var  json = trans.responseText. evalJSON (); if  (json.message) { var  msg = json.message +  '<br />' ; $(messages_div). insert (msg); } }   poll_server (); }
Long Polling – 1 server <?php $query  =  'SELECT message FROM messages WHERE dateadded > ?' ; $stmt   =  $pdo -> prepare ( $query ); while  (true) { $message  =  $stmt -> execute ( $cursor_date ); if  (! empty ( $message )) { echo   json_encode ( $message ); break ; } } ?>
Long Polling – 1 server ,[object Object],[object Object],[object Object],[object Object]
Long Polling – 1 server ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Long Polling – 2 servers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Long Polling – 2 servers web server polling server HTTP XHR over HTTP
Long Polling – 2 servers ,[object Object],[object Object],[object Object],[object Object],[object Object]
Long Polling – 2 servers ,[object Object],[object Object],[object Object],[object Object]
Long Polling – 2 servers function   poll_server () { new  Ajax. Request ( this .urlPolling, { method:  'post' , parameters: data, onSuccess:  this .successHandler, onFailure:  this .handleFailure, onException:  this .handleException }); } document. observe ( 'dom:loaded' , poll_server);
Long Polling – 2 servers function   successHandler (trans, messages_div) { if  (trans.responseText) { var  json = trans.responseText. evalJSON (); if  (json.message) { var  msg = json.message +  '<br />' ; $(messages_div). insert (msg); } }   poll_server (); }
Long Polling – 2 servers Main Web Server Polling Server <?php $query  =  'INSERT INTO messages VALUES (?, ?)' ; $stmt   =  $pdo -> prepare ( $query ); $stmt -> prepare ( $message ,  $date ); $polling_server -> send ( $message ); ?> <?php foreach  ( $this ->waiting  as   $connection ){ $connection -> respond ( $message ); } ?>
Long Polling – 2 servers ,[object Object],[object Object],[object Object],[object Object]
Long Polling – 2 servers ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
WebSockets ,[object Object],[object Object]
WebSockets ,[object Object],[object Object],[object Object],[object Object]
WebSockets ,[object Object],[object Object],[object Object],[object Object],[object Object]
WebSockets web server WebSocket server JSON via WebSockets
WebSockets ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
WebSockets ,[object Object],[object Object],[object Object],[object Object]
WebSockets function   poll_server () { var  socket =  new   WebSocket ( 'ws://example.com/' ); socket.onmessage =  function  (response) { successHandler (response,  'message_errors' ); } } document. observe ( 'dom:loaded' , poll_server);
WebSockets function   successHandler (trans, messages_div) { if  (trans.data) { var  json = trans.data. evalJSON (); if  (json.message) { var  msg = json.message +  '<br />' ; $(messages_div). insert (msg); } } }
WebSockets Main Web Server WebSocket Server <?php $query  =  'INSERT INTO messages VALUES (?, ?)' ; $stmt   =  $pdo -> prepare ( $query ); $stmt -> prepare ( $message ,  $date ); $polling_server -> send ( $message ); ?> <?php foreach  ( $this ->waiting  as   $connection ){ $connection -> respond ( $message ); } ?>
WebSockets ,[object Object],[object Object],[object Object],[object Object]
WebSockets ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
WebSockets ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
WaterSpout ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
WaterSpout ,[object Object],[object Object],[object Object],[object Object],[object Object]
WaterSpout - Listeners <?php public function   listen () { // Handle cursor for long polling fall back. // ... $this ->dispatcher-> add_listener ( $this );  } ?>
WaterSpout - Dispatcher <?php /* Called every .25 seconds on all waiting listeners */ public function   process_event (Controller  $mover  = null) { $key  =  array_search (( int )  $this ->_cursor,  array_keys (self:: $_commands )); if  ( $key  === false && ! is_null ( $this ->_cursor)) { return ; } $commands  =  array_slice (self:: $_commands ,  $key ); if  ( empty ( $commands )) { return ; } $response  =  new   HTTPResponse ( 200 ); $body   =  array ( '__URI__'   =>  $this ->uri,  'commands'  =>  $commands, 'cursor'   =>  end ( array_keys (self:: $_commands )) +  1 ); $response -> set_body ( $body , true); $this -> write ( $response ); $this ->_cursor = ( int )  end ( array_keys (self:: $_commands )) +  1 ; } ?>
WaterSpout vs Apache/Nginx ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
WebSockets ,[object Object],[object Object],[object Object],[object Object]
Questions? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

Nginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصولNginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصول
efazati
 
Ngrep commands
Ngrep commandsNgrep commands
Ngrep commands
Rishu Seth
 
skipfish
skipfishskipfish
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
Zabbix
 
Teach your (micro)services talk Protocol Buffers with gRPC.
Teach your (micro)services talk Protocol Buffers with gRPC.Teach your (micro)services talk Protocol Buffers with gRPC.
Teach your (micro)services talk Protocol Buffers with gRPC.
Mihai Iachimovschi
 
PM : code faster
PM : code fasterPM : code faster
PM : code faster
PHPPRO
 
From zero to almost rails in about a million slides...
From zero to almost rails in about a million slides...From zero to almost rails in about a million slides...
From zero to almost rails in about a million slides...
david_e_worth
 
Bleeding secrets
Bleeding secretsBleeding secrets
Bleeding secrets
Ofer Rivlin, CISSP
 
Web server working
Web server workingWeb server working
Web server working
Prem Joshua
 
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
Moabi.com
 
NginX - good practices, tips and advanced techniques
NginX - good practices, tips and advanced techniquesNginX - good practices, tips and advanced techniques
NginX - good practices, tips and advanced techniques
Claudio Borges
 
Linux kernel TLS и HTTPS / Александр Крижановский (Tempesta Technologies)
Linux kernel TLS и HTTPS / Александр Крижановский (Tempesta Technologies)Linux kernel TLS и HTTPS / Александр Крижановский (Tempesta Technologies)
Linux kernel TLS и HTTPS / Александр Крижановский (Tempesta Technologies)
Ontico
 
From zero to hero - Easy log centralization with Logstash and Elasticsearch
From zero to hero - Easy log centralization with Logstash and ElasticsearchFrom zero to hero - Easy log centralization with Logstash and Elasticsearch
From zero to hero - Easy log centralization with Logstash and Elasticsearch
Rafał Kuć
 
MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011
Mike Willbanks
 
Relayd: a load balancer for OpenBSD
Relayd: a load balancer for OpenBSD Relayd: a load balancer for OpenBSD
Relayd: a load balancer for OpenBSD
Giovanni Bechis
 
Puppet
PuppetPuppet
Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4
Ilya Haykinson
 
Locker: distributed consistent locking
Locker: distributed consistent lockingLocker: distributed consistent locking
Locker: distributed consistent locking
Knut Nesheim
 
Nginx + PHP
Nginx + PHPNginx + PHP
Nginx + PHP
Wataru OKAMOTO
 
!!! Huong dan !!!
!!! Huong dan !!!!!! Huong dan !!!
!!! Huong dan !!!
Ngoc Huynh (Nina)
 

What's hot (20)

Nginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصولNginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصول
 
Ngrep commands
Ngrep commandsNgrep commands
Ngrep commands
 
skipfish
skipfishskipfish
skipfish
 
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
Rihards Olups - Encrypting Daemon Traffic With Zabbix 3.0
 
Teach your (micro)services talk Protocol Buffers with gRPC.
Teach your (micro)services talk Protocol Buffers with gRPC.Teach your (micro)services talk Protocol Buffers with gRPC.
Teach your (micro)services talk Protocol Buffers with gRPC.
 
PM : code faster
PM : code fasterPM : code faster
PM : code faster
 
From zero to almost rails in about a million slides...
From zero to almost rails in about a million slides...From zero to almost rails in about a million slides...
From zero to almost rails in about a million slides...
 
Bleeding secrets
Bleeding secretsBleeding secrets
Bleeding secrets
 
Web server working
Web server workingWeb server working
Web server working
 
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
 
NginX - good practices, tips and advanced techniques
NginX - good practices, tips and advanced techniquesNginX - good practices, tips and advanced techniques
NginX - good practices, tips and advanced techniques
 
Linux kernel TLS и HTTPS / Александр Крижановский (Tempesta Technologies)
Linux kernel TLS и HTTPS / Александр Крижановский (Tempesta Technologies)Linux kernel TLS и HTTPS / Александр Крижановский (Tempesta Technologies)
Linux kernel TLS и HTTPS / Александр Крижановский (Tempesta Technologies)
 
From zero to hero - Easy log centralization with Logstash and Elasticsearch
From zero to hero - Easy log centralization with Logstash and ElasticsearchFrom zero to hero - Easy log centralization with Logstash and Elasticsearch
From zero to hero - Easy log centralization with Logstash and Elasticsearch
 
MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011
 
Relayd: a load balancer for OpenBSD
Relayd: a load balancer for OpenBSD Relayd: a load balancer for OpenBSD
Relayd: a load balancer for OpenBSD
 
Puppet
PuppetPuppet
Puppet
 
Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4Why and How Powershell will rule the Command Line - Barcamp LA 4
Why and How Powershell will rule the Command Line - Barcamp LA 4
 
Locker: distributed consistent locking
Locker: distributed consistent lockingLocker: distributed consistent locking
Locker: distributed consistent locking
 
Nginx + PHP
Nginx + PHPNginx + PHP
Nginx + PHP
 
!!! Huong dan !!!
!!! Huong dan !!!!!! Huong dan !!!
!!! Huong dan !!!
 

Viewers also liked

Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
Steve Rhoades
 
Open a window, see the clouds - php|tek 2011
Open a window, see the clouds - php|tek 2011Open a window, see the clouds - php|tek 2011
Open a window, see the clouds - php|tek 2011
Rafael Dohms
 
Aplicaciones en tiempo real con nodejs y html5
Aplicaciones en tiempo real con nodejs y html5Aplicaciones en tiempo real con nodejs y html5
Aplicaciones en tiempo real con nodejs y html5
programadoresmx
 
App en tiempo real con HTML5+Node.js+Socket.IO
App en tiempo real con HTML5+Node.js+Socket.IOApp en tiempo real con HTML5+Node.js+Socket.IO
App en tiempo real con HTML5+Node.js+Socket.IO
Walter Gerez
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
Dhruva Krishnan
 
5 Tornados Intro
5 Tornados Intro5 Tornados Intro
5 Tornados Intro
Ecumene
 
Waterspout
WaterspoutWaterspout
Waterspout
rendrafauzi
 
TORNADOS
TORNADOSTORNADOS
TORNADOS
simran
 
Water slideshare
Water slideshareWater slideshare
Water slideshare
Wendy Ely
 
Angular workflow with gulp.js
Angular workflow with gulp.jsAngular workflow with gulp.js
Angular workflow with gulp.js
Cihad Horuzoğlu
 
Hybrid Apps with Angular & Ionic Framework
Hybrid Apps with Angular & Ionic FrameworkHybrid Apps with Angular & Ionic Framework
Hybrid Apps with Angular & Ionic Framework
Cihad Horuzoğlu
 
Water presentation
Water presentationWater presentation
Water presentation
melissa banguero
 
Water Resources Power Point Presentation
Water Resources Power Point PresentationWater Resources Power Point Presentation
Water Resources Power Point Presentation
natalia97
 

Viewers also liked (13)

Asynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time MessagingAsynchronous PHP and Real-time Messaging
Asynchronous PHP and Real-time Messaging
 
Open a window, see the clouds - php|tek 2011
Open a window, see the clouds - php|tek 2011Open a window, see the clouds - php|tek 2011
Open a window, see the clouds - php|tek 2011
 
Aplicaciones en tiempo real con nodejs y html5
Aplicaciones en tiempo real con nodejs y html5Aplicaciones en tiempo real con nodejs y html5
Aplicaciones en tiempo real con nodejs y html5
 
App en tiempo real con HTML5+Node.js+Socket.IO
App en tiempo real con HTML5+Node.js+Socket.IOApp en tiempo real con HTML5+Node.js+Socket.IO
App en tiempo real con HTML5+Node.js+Socket.IO
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
5 Tornados Intro
5 Tornados Intro5 Tornados Intro
5 Tornados Intro
 
Waterspout
WaterspoutWaterspout
Waterspout
 
TORNADOS
TORNADOSTORNADOS
TORNADOS
 
Water slideshare
Water slideshareWater slideshare
Water slideshare
 
Angular workflow with gulp.js
Angular workflow with gulp.jsAngular workflow with gulp.js
Angular workflow with gulp.js
 
Hybrid Apps with Angular & Ionic Framework
Hybrid Apps with Angular & Ionic FrameworkHybrid Apps with Angular & Ionic Framework
Hybrid Apps with Angular & Ionic Framework
 
Water presentation
Water presentationWater presentation
Water presentation
 
Water Resources Power Point Presentation
Water Resources Power Point PresentationWater Resources Power Point Presentation
Water Resources Power Point Presentation
 

Similar to Realtime Communication Techniques with PHP

Taking a Quantum Leap with Html 5 WebSocket
Taking a Quantum Leap with Html 5 WebSocketTaking a Quantum Leap with Html 5 WebSocket
Taking a Quantum Leap with Html 5 WebSocket
Shahriar Hyder
 
Http request&response by Vignesh 15 MAR 2014
Http request&response by Vignesh 15 MAR 2014Http request&response by Vignesh 15 MAR 2014
Http request&response by Vignesh 15 MAR 2014
Navaneethan Naveen
 
EAI design patterns/best practices
EAI design patterns/best practicesEAI design patterns/best practices
EAI design patterns/best practices
Ajit Bhingarkar
 
10135 a 05
10135 a 0510135 a 05
10135 a 05
Bố Su
 
CSE422 Section 002 – Computer Networking Fall 2018 Ho.docx
CSE422 Section 002 – Computer Networking Fall 2018  Ho.docxCSE422 Section 002 – Computer Networking Fall 2018  Ho.docx
CSE422 Section 002 – Computer Networking Fall 2018 Ho.docx
mydrynan
 
Http request&response session 1 - by Vignesh.N
Http request&response session 1 - by Vignesh.NHttp request&response session 1 - by Vignesh.N
Http request&response session 1 - by Vignesh.N
Navaneethan Naveen
 
Introduction to HTTP
Introduction to HTTPIntroduction to HTTP
Introduction to HTTP
Seble Nigussie
 
Difference between Client Polling vs Server Push vs Websocket vs Long Polling
Difference between Client Polling vs Server Push vs Websocket vs Long PollingDifference between Client Polling vs Server Push vs Websocket vs Long Polling
Difference between Client Polling vs Server Push vs Websocket vs Long Polling
jeetendra mandal
 
Under the Covers with the Web
Under the Covers with the WebUnder the Covers with the Web
Under the Covers with the Web
Trevor Lohrbeer
 
Application layer
Application layerApplication layer
Application layer
rohit nimbalkar
 
Web Real-time Communications
Web Real-time CommunicationsWeb Real-time Communications
Web Real-time Communications
Alexei Skachykhin
 
Understanding the Web through HTTP
Understanding the Web through HTTPUnderstanding the Web through HTTP
Understanding the Web through HTTP
Olivia Brundage
 
DNS & HTTP overview
DNS & HTTP overviewDNS & HTTP overview
DNS & HTTP overview
Roman Wlodarski
 
Fight empire-html5
Fight empire-html5Fight empire-html5
Fight empire-html5
Bhakti Mehta
 
Computer networks module 5 content covered in this ppt
Computer networks module 5 content covered in this pptComputer networks module 5 content covered in this ppt
Computer networks module 5 content covered in this ppt
vinuthak18
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
JUW Jinnah University for Women
 
Performance #4 network
Performance #4  networkPerformance #4  network
Performance #4 network
Vitali Pekelis
 
Comet / WebSocket Web Applications
Comet / WebSocket Web ApplicationsComet / WebSocket Web Applications
Comet / WebSocket Web Applications
Codemotion
 
Hypertex transfer protocol
Hypertex transfer protocolHypertex transfer protocol
Hypertex transfer protocol
wanangwa234
 
Appl layer
Appl layerAppl layer
Appl layer
rajanikant
 

Similar to Realtime Communication Techniques with PHP (20)

Taking a Quantum Leap with Html 5 WebSocket
Taking a Quantum Leap with Html 5 WebSocketTaking a Quantum Leap with Html 5 WebSocket
Taking a Quantum Leap with Html 5 WebSocket
 
Http request&response by Vignesh 15 MAR 2014
Http request&response by Vignesh 15 MAR 2014Http request&response by Vignesh 15 MAR 2014
Http request&response by Vignesh 15 MAR 2014
 
EAI design patterns/best practices
EAI design patterns/best practicesEAI design patterns/best practices
EAI design patterns/best practices
 
10135 a 05
10135 a 0510135 a 05
10135 a 05
 
CSE422 Section 002 – Computer Networking Fall 2018 Ho.docx
CSE422 Section 002 – Computer Networking Fall 2018  Ho.docxCSE422 Section 002 – Computer Networking Fall 2018  Ho.docx
CSE422 Section 002 – Computer Networking Fall 2018 Ho.docx
 
Http request&response session 1 - by Vignesh.N
Http request&response session 1 - by Vignesh.NHttp request&response session 1 - by Vignesh.N
Http request&response session 1 - by Vignesh.N
 
Introduction to HTTP
Introduction to HTTPIntroduction to HTTP
Introduction to HTTP
 
Difference between Client Polling vs Server Push vs Websocket vs Long Polling
Difference between Client Polling vs Server Push vs Websocket vs Long PollingDifference between Client Polling vs Server Push vs Websocket vs Long Polling
Difference between Client Polling vs Server Push vs Websocket vs Long Polling
 
Under the Covers with the Web
Under the Covers with the WebUnder the Covers with the Web
Under the Covers with the Web
 
Application layer
Application layerApplication layer
Application layer
 
Web Real-time Communications
Web Real-time CommunicationsWeb Real-time Communications
Web Real-time Communications
 
Understanding the Web through HTTP
Understanding the Web through HTTPUnderstanding the Web through HTTP
Understanding the Web through HTTP
 
DNS & HTTP overview
DNS & HTTP overviewDNS & HTTP overview
DNS & HTTP overview
 
Fight empire-html5
Fight empire-html5Fight empire-html5
Fight empire-html5
 
Computer networks module 5 content covered in this ppt
Computer networks module 5 content covered in this pptComputer networks module 5 content covered in this ppt
Computer networks module 5 content covered in this ppt
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 
Performance #4 network
Performance #4  networkPerformance #4  network
Performance #4 network
 
Comet / WebSocket Web Applications
Comet / WebSocket Web ApplicationsComet / WebSocket Web Applications
Comet / WebSocket Web Applications
 
Hypertex transfer protocol
Hypertex transfer protocolHypertex transfer protocol
Hypertex transfer protocol
 
Appl layer
Appl layerAppl layer
Appl layer
 

Recently uploaded

FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
Data Hops
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
marufrahmanstratejm
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 

Recently uploaded (20)

FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3FREE A4 Cyber Security Awareness  Posters-Social Engineering part 3
FREE A4 Cyber Security Awareness Posters-Social Engineering part 3
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Public CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptxPublic CyberSecurity Awareness Presentation 2024.pptx
Public CyberSecurity Awareness Presentation 2024.pptx
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 

Realtime Communication Techniques with PHP

  • 1. Realtime Communication Techniques with PHP Scott Mattocks & Chris Lewis, OnForce, Inc.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. Refresh database web server web server
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. Short Polling database web server web server
  • 20.
  • 21. Short Polling function poll_server () { new Ajax. Request ( this .urlPolling, { method: 'post' , parameters: data, onSuccess: this .successHandler, onFailure: this .handleFailure, onException: this .handleException }); } setInterval ( 'poll_server()' , 5000 );
  • 22. Short Polling function successHandler (trans, messages_div) { if (trans.responseText) { var json = trans.responseText. evalJSON (); if (json.message) { var msg = json.message + '<br />' ; $(messages_div). insert (msg); } } }
  • 23. Short Polling function successHandler (trans, messages_div) { if (trans.responseText) { var json = trans.responseText. evalJSON (); if (json.message) { var msg = json.message + '<br />' ; $(messages_div). insert (msg); } } }
  • 24.
  • 25.
  • 26.
  • 27. Long Polling – 1 server database web server web server
  • 28.
  • 29.
  • 30. Long Polling – 1 server function poll_server () { new Ajax. Request ( this .urlPolling, { method: 'post' , parameters: data, onSuccess: this .successHandler, onFailure: this .handleFailure, onException: this .handleException }); } document. observe ( 'dom:loaded' , poll_server);
  • 31. Long Polling – 1 server function successHandler (trans, messages_div) { if (trans.responseText) { var json = trans.responseText. evalJSON (); if (json.message) { var msg = json.message + '<br />' ; $(messages_div). insert (msg); } } poll_server (); }
  • 32. Long Polling – 1 server <?php $query = 'SELECT message FROM messages WHERE dateadded > ?' ; $stmt = $pdo -> prepare ( $query ); while (true) { $message = $stmt -> execute ( $cursor_date ); if (! empty ( $message )) { echo json_encode ( $message ); break ; } } ?>
  • 33.
  • 34.
  • 35.
  • 36. Long Polling – 2 servers web server polling server HTTP XHR over HTTP
  • 37.
  • 38.
  • 39. Long Polling – 2 servers function poll_server () { new Ajax. Request ( this .urlPolling, { method: 'post' , parameters: data, onSuccess: this .successHandler, onFailure: this .handleFailure, onException: this .handleException }); } document. observe ( 'dom:loaded' , poll_server);
  • 40. Long Polling – 2 servers function successHandler (trans, messages_div) { if (trans.responseText) { var json = trans.responseText. evalJSON (); if (json.message) { var msg = json.message + '<br />' ; $(messages_div). insert (msg); } } poll_server (); }
  • 41. Long Polling – 2 servers Main Web Server Polling Server <?php $query = 'INSERT INTO messages VALUES (?, ?)' ; $stmt = $pdo -> prepare ( $query ); $stmt -> prepare ( $message , $date ); $polling_server -> send ( $message ); ?> <?php foreach ( $this ->waiting as $connection ){ $connection -> respond ( $message ); } ?>
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47. WebSockets web server WebSocket server JSON via WebSockets
  • 48.
  • 49.
  • 50. WebSockets function poll_server () { var socket = new WebSocket ( 'ws://example.com/' ); socket.onmessage = function (response) { successHandler (response, 'message_errors' ); } } document. observe ( 'dom:loaded' , poll_server);
  • 51. WebSockets function successHandler (trans, messages_div) { if (trans.data) { var json = trans.data. evalJSON (); if (json.message) { var msg = json.message + '<br />' ; $(messages_div). insert (msg); } } }
  • 52. WebSockets Main Web Server WebSocket Server <?php $query = 'INSERT INTO messages VALUES (?, ?)' ; $stmt = $pdo -> prepare ( $query ); $stmt -> prepare ( $message , $date ); $polling_server -> send ( $message ); ?> <?php foreach ( $this ->waiting as $connection ){ $connection -> respond ( $message ); } ?>
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58. WaterSpout - Listeners <?php public function listen () { // Handle cursor for long polling fall back. // ... $this ->dispatcher-> add_listener ( $this ); } ?>
  • 59. WaterSpout - Dispatcher <?php /* Called every .25 seconds on all waiting listeners */ public function process_event (Controller $mover = null) { $key = array_search (( int ) $this ->_cursor, array_keys (self:: $_commands )); if ( $key === false && ! is_null ( $this ->_cursor)) { return ; } $commands = array_slice (self:: $_commands , $key ); if ( empty ( $commands )) { return ; } $response = new HTTPResponse ( 200 ); $body = array ( '__URI__' => $this ->uri, 'commands' => $commands, 'cursor' => end ( array_keys (self:: $_commands )) + 1 ); $response -> set_body ( $body , true); $this -> write ( $response ); $this ->_cursor = ( int ) end ( array_keys (self:: $_commands )) + 1 ; } ?>
  • 60.
  • 61.
  • 62.

Editor's Notes

  1. - Once upon a time, the internet was flat. Users asked for content and web servers gave it to them. - XMLHttpRequest came along and change all of that. - Google said “well, we know they are going to ask for their new messages soon anyway, so why not give them the new messages before they ask?”
  2. - Unless you are Facebook, the database is your bottle neck. - Solutions that consume database resources are not very scalable - Timeliness is often sacrificed for scalability
  3. Basically the same as refresh but with less data transfered