Upstart: Good or bad idea?

edited Sep '16

Well you should look for phppm if you want something similar, it's based on react php

I even started working on phalcon adapter. But after tests it's slower(!) than fpm + nginx so i dropped it.


one of my services


description "Php workers for my site"
author "izo"

start on startup
stop on shutdown

 sudo -u www-data /opt/php-5614/bin/php -f /var/www/html/workers/run_worker.php >> /var/log/run_worker.log
end script
edited Sep '16

With OPcache, bootstrap of the application with it's ENV should not put too much overhead, i.e. your index.php, loader.php, services.php etc. will be cached and served from RAM after they got first hit.

If you guys have a chance to work with some shitware like Magento(2), you'll see what it means to run with a shitload of overhead. In LAN 1Gbps env, it cannot load page below 1 second (1000 ms). Phalcon does it with 12ms. Raw PHP 5ms. :) Same VM with 4 cores @4200Mhz.


Ubuntu 16.04

cat /usr/local/bin/systemd-email


//php -v or whatever you need

cat /lib/systemd/system/phpworkers.service

//remove this and keep this line blank at the 1st row
Description=Php workers



service phpworkers stop/start/status

edited Sep '16

Are you sure your example is correct? You're executing email systemd service/unit? Why? :S

This is unit definition for PHP:

cat /lib/systemd/system/php7.0-fpm.service 
Description=The PHP 7.0 FastCGI Process Manager

ExecStart=/usr/sbin/php-fpm7.0 --nodaemonize --fpm-config /etc/php/7.0/fpm/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID


To be honest im not sure if Izo understand a problem. OP is looking for event based, not io blocking php daemon. Like whole application bootstraped once and kept in memory which php-pm or php react is doing.


what I understood was how to create a service that starts with system and restart itself when error happen. Maybe i am wrong ...

I am using my script and its working and the only difference i saw was they have som eextra steps in fpm. probably they are killing zombies in reload or something like that.

No, basic idea is to have a daemonized application. That way, all defined services, configuration, etc. are loaded only once during initial run (@reboot). The process keeps running permanently as a daemon on the server (background), and ready to accept work from web server. Similar to PHP-FPM worker processes but only with full bootstrap initialized and kept in RAM as @Jurigag already described here.