Skip to content

Commit

Permalink
add dispatchSignal method
Browse files Browse the repository at this point in the history
  • Loading branch information
white-poto committed Jan 24, 2017
1 parent 997e4e8 commit 4d934e0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ count is less then N+1 forever.

Notice
--------------------------
+ Remember that you must add `declare(ticks=n);` at the start of program.
+ Remember that you should call the `Process::dispatchSignal` method to call
call signal handlers for pending signals.
+ It is not recommend that adding `declare(ticks=n);` at the start of program
to handle the pending signals.
+ A better way to handle the single is that calling `pcntl_signal_dispatch`
instead of `declare` which is more is a waste of CPU resources
+ If the sub processes exit continually and quickly, you should set `n` to
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jenner/simple_fork",
"description": "simple multi process manager based on pcntl",
"version": "1.1.3",
"version": "1.2.0",
"keywords": [
"fork",
"process manager",
Expand Down
11 changes: 11 additions & 0 deletions src/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,17 @@ public function registerSignalHandler($signal, callable $handler)
$this->signal_handlers[$signal] = $handler;
}

/**
* after php-5.3.0, we can call pcntl_singal_dispatch to call signal handlers for pending signals
* which can save cpu resources than using declare(tick=n)
*
* @return bool
*/
public function dispatchSignal()
{
return pcntl_signal_dispatch();
}

/**
* you should overwrite this function
* if you do not use the Runnable or callback.
Expand Down

0 comments on commit 4d934e0

Please sign in to comment.