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 Slide

  2. Johan Janssens

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

    View 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 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 Slide

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

    View 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 Slide

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

    View 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 Slide

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

    View Slide

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

    View Slide

  11. A demo to get started…

    View Slide

  12. serversideup/php:8.1-fpm-nginx

    View Slide

  13. Hosting options …

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  17. https://railway.app/

    View Slide

  18. https://render.com/

    View Slide

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

    View Slide

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

    View Slide

  21. Let’s add some toys!

    View Slide

  22. 5
    Adding an OpenSwoole HTTP Service

    View Slide

  23. 6
    Adding an OpenSwoole HTTP Service
    oneshot
    longrun

    View Slide

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

    View Slide

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

    View Slide

  26. Another demo to get going…

    View Slide

  27. serversideup/php:8.1-fpm-nginx

    View Slide

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

    View Slide