travail/parallel-prefork
最新稳定版本:v0.2.1
Composer 安装命令:
composer require travail/parallel-prefork
包简介
A simple prefork server framework
README 文档
README
NAME
Parallel\Prefork - A simple prefork server framework
SYNOPSIS
<?php use \Parallel\Prefork; require_once '/path/to/vendor/autoload.php'; $pp = new Prefork([ 'max_workers' => 5, 'trap_signals' => [ SIGHUP => SIGTERM, SIGTERM => SIGTERM, ], ]); while ($pp->signalReceived() !== SIGTERM) { if ($pp->start()) { continue; } // ... do some work within the child process ... $pp->finish(); } $pp->waitAllChildren();
INSTALLATION
To install this package into your project via composer, add the following snippet to your composer.json. Then run composer install.
"require": { "travail/parallel-prefork": "dev-master" } If you want to install from github, add the following:
"repositories": [ { "type": "vcs", "url": "git@github.com:travail/php-Parallel-Prefork.git" } ] DESCRIPTION
Parallel\Prefork supports graceful shutdown and run-time reconfiguration.
DEPENDENCIES
- posix
- pcntl
METHODS
__construct
Parallel\Prefork __construct([ 'max_workers' => int $max_workers, 'err_respawn_interval' => int $err_respawn_interval, 'trap_signals' => [int $signal_trapped_in_parent_process => int $signal_sent_to_child_processes], ])
Instantiation. Takes an array as an argument. Recognized parameters are as follows.
max_workers
Number of worker processes (default: 3)
trap_signals
Array of signals to be trapped. Manager process will trap the signals listed in the keys of the array, and send the signal specified in the associated value (if any) to all worker processes.
err_respawn_interval
Number of seconds to deter spawning of child processes after a worker exits abnormally (default: 1)
start
bool start() The main routine. Returns undef in child processes. Returns a true within manager process upon receiving a signal specified in the trapSignals array.
finish
void finish(int $exit_code)
Child processes should call this function for termination. Takes exit code as an optional argument. Only usable from child processes.
signalAllChildren
void signalAllChildren(int $signal)
Sends signal to all worker processes. Only usable from manager process.
waitAllChildren
void waitAllChildren() Blocks until all worker processes exit. Only usable from manager process.
signalReceived
int signalReceived() Returns a signal manager process trapped.
THANKS TO
AUTHOR
travail
LICENSE
This library is free software. You can redistribute it and/or modify it under the same terms as PHP itself.
统计信息
- 总下载量: 183.33k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 39
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: PHP-3.0
- 更新时间: 2026-01-04