SlideShare una empresa de Scribd logo
1 de 21
Aplicaciones en
   tiempo real
WebSockets y PHP
¿Quién soy?
● Ingeniero en Informática
  Facultad de Informática UPM

● Me apasiona el mundo web
  y nuevas tecnologías

● Trabajo en Unidad Editorial
Web
                         GET /hola.html

      Cliente                                   Servidor
                             200 OK




                1.   Unidireccional

                2.   Alta latencia

                3.   "Stateless" (peticiones independientes)
sockets


   "Concepto abstracto por el cual dos procesos pueden
intercambiar información de manera fiable y ordenada, y
    este queda definido por un par de IPs, puertos y un
                protocolo de transporte"
Websockets
"Websocket es una tecnología que proporciona
 un canal de comunicación bidireccional y full-
  duplex sobre un único socket a través de la
                    WEB"

     Cliente                         Servidor




                Bi-direccional
                Baja latencia
                Bajo overhead
Tiempo real

                   Y ...

 ¿Cómo han funcionado las aplicaciones en
      tiempo real hasta entonces?
Tiempo real - Polling




   Fuente: http://dsheiko.com/weblog/websockets-vs-sse-vs-long-polling
Tiempo real - Websockets




   Fuente: http://dsheiko.com/weblog/websockets-vs-sse-vs-long-polling
Websockets



  Protocolo
              API
  RFC 6455
Websockets - Protocolo




    Fuente: http://msdn.microsoft.com/es-es/magazine/hh975342.aspx
Websockets - Protocolo

                                         PETICIÓN
GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Origin: http://example.com




                                       RESPUESTA
HTTP/1.1 101 WebSocket Protocol Handshake
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Websockets - API
                 Inicialización
     var ws = new WebSocket("ws://example.com")


                Envio de datos
                     send(data)


                    Eventos
                      onopen
                    onmessage
                      onclose
                      onerror
Soporte navegadores




4.0 +   10+   6.0+    10.7+
Socket.io y Sockjs


"Librerías para el desarrollo de aplicaciones en
tiempo real bajo WebSockets que abstraen los
   diferentes mecanismos de comunicación"

                   http://socket.io/

        https://github.com/sockjs/sockjs-client
Comet vs Websockets -
Overhead




  Comparación de overhead de información innecesaria entre Comet y WebSocket
                Fuente: http://www.websocket.org/quantum.html
Comet vs Websockets -
Latencia
DEMO WebSockets - Chat

  Cliente 1
                     Servidor
                     Pila asíncrona

  Cliente 2          Aplicación

                         Ratchet




  Cliente n
DEMO Websockets -
Tareas
 Servidor              Servidor
 Pila síncrona         Pila asíncrona
 Aplicación

                       Aplicación

                 *MQ
                         Ratchet
DEMO Websockets -
Tareas
                                                          Ac
                                      Cliente                 ep
                                                Pe              ta
                                                  tic                W
                                                      ión               eb
                     1                                                     so
                                                            W                   ck
                                                               eb                   et
                                                                   so                    Co
                st




                                                                     ck
               /li




                                                                          et               ne
           sk




                                                          3
                             et




                                                                               Co             xió
         /ta




                             ck




                                  2                                                              n   4
                           so




                                                                                 ne
      ET




                         eb




                                                                                     xió
     G




                     W




                                                                                          n
                     +
                 L
               TM
           H




   Servidor                                                                                     Servidor
  (síncrona)                                                                                  (asíncrona)
DEMO Websockets -
Tareas

                                        Cliente
                           5
                                                      Ac
                                                        tu
                                                           al
                      et




                                                             iza
                     at
                 pd




                                                                ció
                /u




                                                                   n
            sk




                                                                       ta
                               ST
          /ta




                                                                         re
                             O




                                    7                                       a   9
       ST




                           lP
                      de
     PO




                     ta
                  es
               pu
            es
            R




   Servidor                                                               Servidor
  (síncrona)                                                            (asíncrona)
                               6                  8
¿Preguntas?
     @javiacei
     https://github.com/javiacei
     fco.javier.aceituno@gmail.com


                     Código
https://github.com/javiacei/websockets-php-talk

Más contenido relacionado

Último

Avances tecnológicos del siglo XXI 10-07 eyvana
Avances tecnológicos del siglo XXI 10-07 eyvanaAvances tecnológicos del siglo XXI 10-07 eyvana
Avances tecnológicos del siglo XXI 10-07 eyvanamcerpam
 
Avances tecnológicos del siglo XXI y ejemplos de estos
Avances tecnológicos del siglo XXI y ejemplos de estosAvances tecnológicos del siglo XXI y ejemplos de estos
Avances tecnológicos del siglo XXI y ejemplos de estossgonzalezp1
 
presentación del desensamble y ensamble del equipo de computo en base a las n...
presentación del desensamble y ensamble del equipo de computo en base a las n...presentación del desensamble y ensamble del equipo de computo en base a las n...
presentación del desensamble y ensamble del equipo de computo en base a las n...axelv9257
 
Buenos_Aires_Meetup_Redis_20240430_.pptx
Buenos_Aires_Meetup_Redis_20240430_.pptxBuenos_Aires_Meetup_Redis_20240430_.pptx
Buenos_Aires_Meetup_Redis_20240430_.pptxFederico Castellari
 
presentacion_desamblado_de_una_computadora_base_a_las_normas_de_seguridad.pdf
presentacion_desamblado_de_una_computadora_base_a_las_normas_de_seguridad.pdfpresentacion_desamblado_de_una_computadora_base_a_las_normas_de_seguridad.pdf
presentacion_desamblado_de_una_computadora_base_a_las_normas_de_seguridad.pdfaxelv9257
 
Generaciones de las Computadoras..pdf...
Generaciones de las Computadoras..pdf...Generaciones de las Computadoras..pdf...
Generaciones de las Computadoras..pdf...solanocortezluisalfr
 
How to use Redis with MuleSoft. A quick start presentation.
How to use Redis with MuleSoft. A quick start presentation.How to use Redis with MuleSoft. A quick start presentation.
How to use Redis with MuleSoft. A quick start presentation.FlorenciaCattelani
 
redes informaticas en una oficina administrativa
redes informaticas en una oficina administrativaredes informaticas en una oficina administrativa
redes informaticas en una oficina administrativanicho110
 
Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...
Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...
Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...JohnRamos830530
 
investigación de los Avances tecnológicos del siglo XXI
investigación de los Avances tecnológicos del siglo XXIinvestigación de los Avances tecnológicos del siglo XXI
investigación de los Avances tecnológicos del siglo XXIhmpuellon
 
Innovaciones tecnologicas en el siglo 21
Innovaciones tecnologicas en el siglo 21Innovaciones tecnologicas en el siglo 21
Innovaciones tecnologicas en el siglo 21mariacbr99
 
EVOLUCION DE LA TECNOLOGIA Y SUS ASPECTOSpptx
EVOLUCION DE LA TECNOLOGIA Y SUS ASPECTOSpptxEVOLUCION DE LA TECNOLOGIA Y SUS ASPECTOSpptx
EVOLUCION DE LA TECNOLOGIA Y SUS ASPECTOSpptxJorgeParada26
 
Guia Basica para bachillerato de Circuitos Basicos
Guia Basica para bachillerato de Circuitos BasicosGuia Basica para bachillerato de Circuitos Basicos
Guia Basica para bachillerato de Circuitos BasicosJhonJairoRodriguezCe
 
infor expo AVANCES TECNOLOGICOS DEL SIGLO 21.pptx
infor expo AVANCES TECNOLOGICOS DEL SIGLO 21.pptxinfor expo AVANCES TECNOLOGICOS DEL SIGLO 21.pptx
infor expo AVANCES TECNOLOGICOS DEL SIGLO 21.pptxgustavovasquezv56
 

Último (14)

Avances tecnológicos del siglo XXI 10-07 eyvana
Avances tecnológicos del siglo XXI 10-07 eyvanaAvances tecnológicos del siglo XXI 10-07 eyvana
Avances tecnológicos del siglo XXI 10-07 eyvana
 
Avances tecnológicos del siglo XXI y ejemplos de estos
Avances tecnológicos del siglo XXI y ejemplos de estosAvances tecnológicos del siglo XXI y ejemplos de estos
Avances tecnológicos del siglo XXI y ejemplos de estos
 
presentación del desensamble y ensamble del equipo de computo en base a las n...
presentación del desensamble y ensamble del equipo de computo en base a las n...presentación del desensamble y ensamble del equipo de computo en base a las n...
presentación del desensamble y ensamble del equipo de computo en base a las n...
 
Buenos_Aires_Meetup_Redis_20240430_.pptx
Buenos_Aires_Meetup_Redis_20240430_.pptxBuenos_Aires_Meetup_Redis_20240430_.pptx
Buenos_Aires_Meetup_Redis_20240430_.pptx
 
presentacion_desamblado_de_una_computadora_base_a_las_normas_de_seguridad.pdf
presentacion_desamblado_de_una_computadora_base_a_las_normas_de_seguridad.pdfpresentacion_desamblado_de_una_computadora_base_a_las_normas_de_seguridad.pdf
presentacion_desamblado_de_una_computadora_base_a_las_normas_de_seguridad.pdf
 
Generaciones de las Computadoras..pdf...
Generaciones de las Computadoras..pdf...Generaciones de las Computadoras..pdf...
Generaciones de las Computadoras..pdf...
 
How to use Redis with MuleSoft. A quick start presentation.
How to use Redis with MuleSoft. A quick start presentation.How to use Redis with MuleSoft. A quick start presentation.
How to use Redis with MuleSoft. A quick start presentation.
 
redes informaticas en una oficina administrativa
redes informaticas en una oficina administrativaredes informaticas en una oficina administrativa
redes informaticas en una oficina administrativa
 
Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...
Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...
Resistencia extrema al cobre por un consorcio bacteriano conformado por Sulfo...
 
investigación de los Avances tecnológicos del siglo XXI
investigación de los Avances tecnológicos del siglo XXIinvestigación de los Avances tecnológicos del siglo XXI
investigación de los Avances tecnológicos del siglo XXI
 
Innovaciones tecnologicas en el siglo 21
Innovaciones tecnologicas en el siglo 21Innovaciones tecnologicas en el siglo 21
Innovaciones tecnologicas en el siglo 21
 
EVOLUCION DE LA TECNOLOGIA Y SUS ASPECTOSpptx
EVOLUCION DE LA TECNOLOGIA Y SUS ASPECTOSpptxEVOLUCION DE LA TECNOLOGIA Y SUS ASPECTOSpptx
EVOLUCION DE LA TECNOLOGIA Y SUS ASPECTOSpptx
 
Guia Basica para bachillerato de Circuitos Basicos
Guia Basica para bachillerato de Circuitos BasicosGuia Basica para bachillerato de Circuitos Basicos
Guia Basica para bachillerato de Circuitos Basicos
 
infor expo AVANCES TECNOLOGICOS DEL SIGLO 21.pptx
infor expo AVANCES TECNOLOGICOS DEL SIGLO 21.pptxinfor expo AVANCES TECNOLOGICOS DEL SIGLO 21.pptx
infor expo AVANCES TECNOLOGICOS DEL SIGLO 21.pptx
 

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Aplicaciones en tiempo real

  • 1. Aplicaciones en tiempo real WebSockets y PHP
  • 2. ¿Quién soy? ● Ingeniero en Informática Facultad de Informática UPM ● Me apasiona el mundo web y nuevas tecnologías ● Trabajo en Unidad Editorial
  • 3. Web GET /hola.html Cliente Servidor 200 OK 1. Unidireccional 2. Alta latencia 3. "Stateless" (peticiones independientes)
  • 4. sockets "Concepto abstracto por el cual dos procesos pueden intercambiar información de manera fiable y ordenada, y este queda definido por un par de IPs, puertos y un protocolo de transporte"
  • 5. Websockets "Websocket es una tecnología que proporciona un canal de comunicación bidireccional y full- duplex sobre un único socket a través de la WEB" Cliente Servidor Bi-direccional Baja latencia Bajo overhead
  • 6. Tiempo real Y ... ¿Cómo han funcionado las aplicaciones en tiempo real hasta entonces?
  • 7. Tiempo real - Polling Fuente: http://dsheiko.com/weblog/websockets-vs-sse-vs-long-polling
  • 8. Tiempo real - Websockets Fuente: http://dsheiko.com/weblog/websockets-vs-sse-vs-long-polling
  • 9. Websockets Protocolo API RFC 6455
  • 10. Websockets - Protocolo Fuente: http://msdn.microsoft.com/es-es/magazine/hh975342.aspx
  • 11. Websockets - Protocolo PETICIÓN GET /chat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Origin: http://example.com RESPUESTA HTTP/1.1 101 WebSocket Protocol Handshake Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
  • 12. Websockets - API Inicialización var ws = new WebSocket("ws://example.com") Envio de datos send(data) Eventos onopen onmessage onclose onerror
  • 13. Soporte navegadores 4.0 + 10+ 6.0+ 10.7+
  • 14. Socket.io y Sockjs "Librerías para el desarrollo de aplicaciones en tiempo real bajo WebSockets que abstraen los diferentes mecanismos de comunicación" http://socket.io/ https://github.com/sockjs/sockjs-client
  • 15. Comet vs Websockets - Overhead Comparación de overhead de información innecesaria entre Comet y WebSocket Fuente: http://www.websocket.org/quantum.html
  • 16. Comet vs Websockets - Latencia
  • 17. DEMO WebSockets - Chat Cliente 1 Servidor Pila asíncrona Cliente 2 Aplicación Ratchet Cliente n
  • 18. DEMO Websockets - Tareas Servidor Servidor Pila síncrona Pila asíncrona Aplicación Aplicación *MQ Ratchet
  • 19. DEMO Websockets - Tareas Ac Cliente ep Pe ta tic W ión eb 1 so W ck eb et so Co st ck /li et ne sk 3 et Co xió /ta ck 2 n 4 so ne ET eb xió G W n + L TM H Servidor Servidor (síncrona) (asíncrona)
  • 20. DEMO Websockets - Tareas Cliente 5 Ac tu al et iza at pd ció /u n sk ta ST /ta re O 7 a 9 ST lP de PO ta es pu es R Servidor Servidor (síncrona) (asíncrona) 6 8
  • 21. ¿Preguntas? @javiacei https://github.com/javiacei fco.javier.aceituno@gmail.com Código https://github.com/javiacei/websockets-php-talk