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

Multiprocess PHP Containers with S6 Overlay - ConFoo 2023

Multiprocess PHP Containers with S6 Overlay - ConFoo 2023

In the pre-container era, the most common way of running PHP applications was with Nginx + PHP-FPM, with containers this is harder as you need two processes: Nginx and PHP-FPM.

S6 Overlay can help to manage multi-process applications in a container - it takes the burden of security aspects, signal handling, configuration and log management off your shoulders & make your code more readable!

URL: https://confoo.ca/en/2023
---
Info about S3 Overlay: https://github.com/just-containers/s6-overlay

Johan Janssens

February 24, 2023
Tweet

More Decks by Johan Janssens

Other Decks in Programming

Transcript

  1. http://www.joomlatools.com/developer @joomlatools
    Multiprocess PHP


    Containers with S6 Overlay

    View full-size slide

  2. Johan Janssens

    Web Developer, Hacker and OpenSwoole Contributor / Evangelist
    @johanjanssens
    johanjanssens
    johanjanssens

    View full-size slide

  3. 1
    In the pre-container era, the most common way of running PHP applications was with
    Nginx + PHP-FPM, with containers this is harder as you need two processes: PHP
    requires a web server process (nginx, apache, caddy, …) and a PHP-FPM process
    in order to run your application
    The Problem

    View full-size slide

  4. 2
    Official PHP Docker Images
    The official PHP Docker images are single process containers offered in 2
    flavours:


    1. PHP + PHPFPM (*)

    2. PHP + Apache (running mod_php)


    (*) In order to use this image variant, some kind of reverse proxy (such as NGINX,
    Apache, or other tool which speaks the FastCGI protocol) will be required.


    More info: https://github.com/docker-library/php

    View full-size slide

  5. http://www.joomlatools.com/developer @joomlatools
    S6 Overlay
    A process supervisor for Docker containers

    View full-size slide

  6. 3
    S6 Overlay can help to manage multi-process applications in a container - it takes the
    burden of security aspects, signal handling, configuration and log management off your
    shoulders & make your code more readable!


    Its based on s6 is a small suite of programs for UNIX, designed to allow process
    supervision (a.k.a service supervision), in the line of daemontools and runit, as well as
    various operations on processes and daemons


    More info:


    • https://skarnet.org/software/s6/


    • https://github.com/just-containers/s6-overlay
    S6 Overlay

    View full-size slide

  7. http://www.joomlatools.com/developer @joomlatools
    Wait... isn't Docker supposed
    to be a "single process per
    container"?

    View full-size slide

  8. 4
    S6 Overlay Philosophy
    There's nothing inherently bad about running multiple processes in a container. The
    more abstract "one thing per container" is our policy - a container should do one thing,
    such as "run a chat service" or "run gitlab." This may involve multiple processes, which
    is fine.


    S6’s interpretation of "The Docker Way" is thus:


    • Containers should do one thing


    • Containers should stop when that thing stops


    If "the thing" fails, then the container should fail, too. We do this by determining which
    processes can restart, and which should bring down the container.

    View full-size slide

  9. https://github.com/serversideup/docker-php

    View full-size slide

  10. https://github.com/serversideup/docker-php
    https://hub.docker.com/r/serversideup/php/

    View full-size slide

  11. A demo to get started…

    View full-size slide

  12. serversideup/php:8.1-fpm-nginx

    View full-size slide

  13. Hosting options …

    View full-size slide

  14. https://www.digitalocean.com/products/app-platform

    View full-size slide

  15. https://cloud.google.com/run

    View full-size slide

  16. https://hub.docker.com/r/serversideup/php/
    https://north
    fl
    ank.com/

    View full-size slide

  17. https://railway.app/

    View full-size slide

  18. https://render.com/

    View full-size slide

  19. https://www.withcoherence.com/

    View full-size slide

  20. https://
    fl
    y.io/
    (*) Only works with S6 Overlay 2.x, requires FROM serversideup/php:8.1-fpm-nginxv1.5.0

    View full-size slide

  21. Let’s add some toys!

    View full-size slide

  22. 5
    Adding an OpenSwoole HTTP Service

    View full-size slide

  23. 6
    Adding an OpenSwoole HTTP Service
    oneshot
    longrun

    View full-size slide

  24. 7
    /var/www/services/swoole/index.php

    View full-size slide

  25. 8
    /var/www/services/fastcgi/index.php

    View full-size slide

  26. Another demo to get going…

    View full-size slide

  27. serversideup/php:8.1-fpm-nginx

    View full-size slide

  28. Who da man ?! Happy coding!
    Please give kudos to @danpostori and @jaydrogers

    View full-size slide