PHP code example of lvinkim / daemon

1. Go to this page and download the library: Download lvinkim/daemon library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lvinkim / daemon example snippets


$ vi /var/www/html/daemon.ini

[worker:1]
command = "/usr/bin/env php /var/www/html/tests/worker/worker-1.php"
enabled = 1

[worker:2]
command = "/usr/bin/env php /var/www/html/tests/worker/worker-2.php"
enabled = 1

[worker:3]
command = "/usr/bin/env php /var/www/html/tests/worker/worker-3.php"
enabled = 1


$ vi /var/www/html/daemon.php


use Lvinkim\Daemon\DaemonMany;

Many($configPath, true);
$daemonMany->run();

$ php /var/www/html/daemon.php
启用 worker:1
启用 worker:2
启用 worker:3
.... 当其中一个 worker 执行完毕,会自动拉起一个新的进程,再次执行此 worker ...

比如要停止 worker:2 , 只需要将 worker:2 的 enabled 配置为 0 
$ vi /var/www/html/daemon.ini

...

[worker:2]
command = "/usr/bin/env php /var/www/html/tests/worker/worker-2.php"
enabled = 0

...