I wonder if anyone has needed to use 'upstart'?
https://blog.bobbyallen.me/2014/06/02/how-to-create-a-php-linux-daemon-service/
|
Sep '16 |
8 |
526 |
0 |
I wonder if anyone has needed to use 'upstart'?
https://blog.bobbyallen.me/2014/06/02/how-to-create-a-php-linux-daemon-service/
Well you should look for phppm if you want something similar, it's based on react php https://github.com/php-pm/php-pm
I even started working on phalcon adapter. But after tests it's slower(!) than fpm + nginx so i dropped it.
one of my services
/etc/init.d/phpworkers-mysite.conf
description "Php workers for my site"
author "izo"
start on startup
stop on shutdown
respawn
script
sudo -u www-data /opt/php-5614/bin/php -f /var/www/html/workers/run_worker.php >> /var/log/run_worker.log
end script
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
#!/bin/bash
//php -v or whatever you need
cat /lib/systemd/system/phpworkers.service
//remove this and keep this line blank at the 1st row
[Unit]
Description=Php workers
Wants=network.target
After=network.target
[Service]
User=www-data
Group=www-data
Restart=always
StandardOutput=syslog
StandardError=syslog
ExecStart=/usr/local/bin/systemd-email
[Install]
WantedBy=multi-user.target
service phpworkers stop/start/status
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
[Unit]
Description=The PHP 7.0 FastCGI Process Manager
After=network.target
[Service]
Type=notify
PIDFile=/run/php/php7.0-fpm.pid
ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf
ExecStart=/usr/sbin/php-fpm7.0 --nodaemonize --fpm-config /etc/php/7.0/fpm/php-fpm.conf
ExecReload=/usr/lib/php/php7.0-fpm-checkconf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
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.