Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Websockets in PHP using Swoole

Websockets in PHP using Swoole

Ricardo Coelho

August 19, 2022
Tweet

More Decks by Ricardo Coelho

Other Decks in Programming

Transcript

  1. Ricardo Coelho - @ramcoelho
    Websockets in PHP using Swoole

    View Slide

  2. Agenda
    Websockets & HTTP/1.1


    Ratchet & Swoole


    Concurrency, asynchrony & parallelism


    Multithread,
    fi
    bers & coroutines


    Shared memory & semaphores


    Streams, gRPC, protobuf, HTTP/2, HTTP/3 & QUIC

    View Slide

  3. Websockets

    View Slide

  4. View Slide

  5. Supervisor

    View Slide

  6. FROM php:8.1.9


    RUN apt-get update \


    && apt-get install -y libssl-dev git zip wget \


    && cd /tmp \


    && wget https://github.com/swoole/swoole-src/archive/refs/heads/master.zip -O swoole-src.zip \


    && unzip swoole-src.zip && cd swoole-src-master \


    && phpize && ./configure && make && make install \


    && cd / && rm -rf /tmp/pear \


    && docker-php-ext-install sockets \


    && docker-php-ext-enable swoole sockets


    nexy/swoole:8.1.9

    View Slide

  7. Ratchet &


    Swoole

    View Slide

  8. View Slide

  9. Concurrency,


    asynchony &


    parallelism

    View Slide

  10. Multithread,


    fibers &


    coroutines

    View Slide

  11. Shared memory &


    semaphores

    View Slide

  12. Websockets vs


    gRPC

    View Slide

  13. HTTP/1.1

    View Slide

  14. TCP/IP

    View Slide

  15. IP +
    Porta
    IP +
    Porta

    View Slide

  16. TCP/IP

    View Slide

  17. View Slide

  18. View Slide

  19. View Slide

  20. HTTP/2 &


    Streams,

    View Slide

  21. Multiplex

    View Slide

  22. TCP/IP

    View Slide

  23. View Slide

  24. HTTP/3 &


    QUIC

    View Slide

  25. QUIC
    QUIC QUIC
    QUIC
    QUIC
    QUIC
    QUIC
    QUIC

    View Slide

  26. Ossification

    View Slide

  27. “Respect the past, and prepare for the
    future by taking action in the present.”
    Rob Martin

    View Slide

  28. UDP
    UDP UDP
    UDP
    UDP
    UDP
    UDP
    UDP

    View Slide

  29. Performance

    View Slide

  30. Conclusion

    View Slide

  31. View Slide

  32. References
    • https://www.rfc-editor.org/rfc/rfc6455


    • https://datatracker.ietf.org/doc/html/rfc9000


    • https://www.rfc-editor.org/rfc/rfc7540.html


    • https://datatracker.ietf.org/doc/html/rfc9114


    • https://unsplash.com


    • http://socketo.me


    • https://openswoole.com


    • https://speakerdeck.com/ramcoelho/swoole


    • https://github.com/nexy/swoole
    The WebSocket Protocol


    QUIC: A UDP-Based Multiplexed and Secure Transport


    Hypertext Transfer Protocol Version 2 (HTTP/2)


    HTTP/3


    Images


    Ratchet Websockets


    Open Swoole


    These slides


    Code used in these slides

    View Slide