Factor #8: Concurrency
Scale out via the process model
Any computer program, once run, is represented by one or more processes. Web apps have taken a variety of process-execution forms. For example, PHP processes run as child processes of Apache, started on demand as needed by request volume.
In the twelve-factor app, processes are a first class citizen.
For example, HTTP requests may be handled by a web process, and long-running background tasks handled by a worker process.
This isn’t anything too new for WordPress sites. As quoted above, both Apache and Nginx already have a method of scaling up needed processes.
Of course it’s not that simple.
Twelve-factor app processes should never daemonize or write PID files. Instead, rely on the operating system’s process manager (such as Upstart, a distributed process manager on a cloud platform, or a tool like Foreman in development) to manage output streams, respond to crashed processes, and handle user-initiated restarts and shutdowns.
If we consider PHP-FPM as an app process, we shouldn’t daemonize it or write a PID file which is the standard setup.
Read this article on running processes for more background on why you run programs instead of starting (daemonizing) them.
- Backing Services
- Build, release, run
- Port binding
- Dev/prod parity
- Admin processes
Want to turn your WordPress site into a Twelve-factor App? Bedrock is a modern WordPress stack to help you get started with the best tools and practices.