Php daemon management

How can I manage my daemon from the Internet without changing the simple cli runtime for php-fpm?

The daemon starts automatically after the OS starts and works as a cli application without the php-fpm pool. Thus, the basic ideology of the demon ecosystem should work without the php-fpm pool (CLI-SAPI).

Server Configuration:

  • Debian 7
  • Apache 2.2
  • php5-fpm (v 5.4.35) - mod_fastcgi
  • daemon.php
  • daemon_manager.php - Management script to run | stop | restart | kill daemon.php from the command line.
  • daemon_manager_web.php - Admin script to control the daemon from the browser.

daemon.php is a regular php daemon as follows:

<?php
    declare(ticks=1);
    ini_set("max_execution_time", "0");
    ini_set("max_input_time",     "0");
    set_time_limit(0);
    /* Catching signals */
    function sig_handler($signo) {
        switch ($signo) {
            case SIGQUIT:
            case SIGTERM:
                // some work
        pcntl_wait($status);
                break;
            //...
        }
    }

    pcntl_signal(SIGTERM, 'signal_handler');
    pcntl_signal(SIGQUIT, 'signal_handler');

    $newpid = pcntl_fork();
    if ($newpid == -1) {
        throw new Exception('Cannot fork porcess');
    } elseif ($newpid) {
        print "Starting daemon under pid=$newpid\n";
        // ...
        exit;
    }

Problem.

PCNTL , , exec(), shell_exec(). , daemon_manager_web.php , , php-fpm.

:

$ ps aux | grep php
root      5952  0.0  2.9  69008 14952 pts/0    S    14:24   0:00 php /var/www/daemon.php

$ service php5-fpm status
php5-fpm.service - LSB: starts php5-fpm
      Loaded: loaded (/etc/init.d/php5-fpm)
      Active: active (running) since Fri, 05 Dec 2014 11:28:25 +0200; 11h ago
     Process: 1003 ExecStart=/etc/init.d/php5-fpm start (code=exited, status=0/SUCCESS)
      CGroup: name=systemd:/system/php5-fpm.service1627 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)9562 php-fpm: pool www9605 php-fpm: pool www9633 php-fpm: pool www

:

$ service php5-fpm status
php5-fpm.service - LSB: starts php5-fpm
      Loaded: loaded (/etc/init.d/php5-fpm)
      Active: active (running) since Fri, 05 Dec 2014 11:28:25 +0200; 11h ago
     Process: 1003 ExecStart=/etc/init.d/php5-fpm start (code=exited, status=0/SUCCESS)
      CGroup: name=systemd:/system/php5-fpm.service1627 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)4987 php-fpm: pool www5040 php-fpm: pool www9432 php-fpm: pool www9492 /usr/bin/php /var/www/daemon.php 
+4
1

Apache. - (, , supervisord, ) (AF_UNIX), socket_select() idle-wait , . , "" ( Apache) .

, PHP , ( ) , (node.js?)

+2
source

All Articles