Last Updated: February 25, 2016
·
2.099K
· sitebase

Heroku PHP Worker

With the following code you can have a PHP worker on Heroku that auto restarts after a crash:

worker.php file

<?php
while (true) {
echo 'Hello world at ' . time() . PHP_EOL;
sleep(1);
}

Procfile

worker: while true; do cd /app/www/ && /app/bin/php worker.php; sleep 1; done

I've also created a gist for this: https://gist.github.com/Sitebase/4065664