https://github.com/takuya/php-daemonize-pcntl
php-daemonize-pcntl
https://github.com/takuya/php-daemonize-pcntl
daemon daemonize pcntl php
Last synced: over 1 year ago
JSON representation
php-daemonize-pcntl
- Host: GitHub
- URL: https://github.com/takuya/php-daemonize-pcntl
- Owner: takuya
- License: gpl-3.0
- Created: 2025-02-14T08:58:51.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-01T01:58:28.000Z (over 1 year ago)
- Last Synced: 2025-03-01T02:31:46.841Z (over 1 year ago)
- Topics: daemon, daemonize, pcntl, php
- Language: PHP
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php-daemonize-pcntl
daemonize function by pcntl_fork.
## php daemon Daemonize all
Daemonize any process , written by php ( pcntl )
## installing
from Packagist
```shell
composer require takuya/php-daemonize-pcntl
```
from GitHub
```shell
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
start(function () { sleep(1000); });
$m->stop();
```
### Run command as daemon
```php
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
```php
#!/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
```shell
./my-server.sh start
./my-server.sh stop
```