graze logo

snack overflow

by the graze technology teams

As systems scale and react to growing user numbers, the way you use and transform your data changes. You’ll probably build towards a system that works around processing queues, batch processing within daemons and pools of workers. There are many languages that are designed with this in mind, but in reality, we sometimes have to deal with this type of system in languages best suited to simpler tasks.

Four, Five, FIRE!

Supervising child processes can be difficult without the proper tools. Processes can fail unexpectedly, logically related scripts won’t know their siblings have disappeared, and extra work will likely ensue. That’s why we’ve written a simple library, aptly named Supervisor, in an attempt to supervise these processes within our PHP applications.

use Graze\Supervisor\ProcessSupervisor;
use Symfony\Component\Process\Process;

$while = new Process('/usr/bin/python');

$sup = new ProcessSupervisor($while);

This will run your process and monitor its status. If the process terminates unexpectedly, the supervisor steps in and attempts to handle it as gracefully as possible. You can configure the supervisor to retry your process, notify your team via pagerduty, or add your own custom handlers.

To find out more about how to use the supervisor library to handle your processes, please read the documentation on github.