takuya / php-daemonize-pcntl
0.1
2025-02-14 09:05 UTC
Requires
- ext-pcntl: *
- ext-posix: *
- ext-shmop: *
Requires (Dev)
This package is auto-updated.
Last update: 2025-03-12 01:53:44 UTC
README
daemonize function by pcntl_fork.
php daemon Daemonize all
Daemonize any process , written by php ( pcntl )
installing
from Packagist
composer require takuya/php-daemonize-pcntl
from GitHub
name='php-daemonize-pcntl' composer config repositories.$name \ vcs https://github.com/takuya/$name composer require takuya/$name:master composer install
Examples
function / Daemonize ( detach tty and parent PID=1)
<?php require_once 'vendor/autoload.php'; use Takuya\PhpDaemonize\PhpDaemonize; /** * Daemonize function */ $m = new PhpDaemonize(); $m->start(function () { sleep(1000); }); $m->stop();
Run command as daemon
<?php require_once 'vendor/autoload.php'; use Takuya\PhpDaemonize\PhpDaemonize; /** * Daemonize function */ $m = new PhpDaemonize(); $m->start(function () { pcntl_exec('/usr/bin/sleep',[10]) });
service (init.d)
this package help to make init.d service
run web server
my-server.sh
#!/usr/bin/env php require_once 'vendor/autoload.php'; use Takuya\PhpDaemonize\PhpDaemonize; $name = 'my-server'; // start stop PhpDaemonize::run_func(function(){ pcntl_exec('/usr/bin/php',['artisan','serve']) },$name);
start and stop
./my-server.sh start ./my-server.sh stop