8000 Fixing PHP notice when child_bucket is not set and some minor coding … · notion/forkdaemon-php@0c2a00f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c2a00f

Browse files
author
Hooman Niktafar
committed
Fixing PHP notice when child_bucket is not set and some minor coding standard fixes
1 parent 9f94029 commit 0c2a00f

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

fork_daemon.php

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,10 @@ public function store_result_get()
466466
public function child_bucket_get()
467467
{
468468
// this function does not apply to the parent
469-
if (self::$parent_pid == getmypid()) return false;
469+
if (self::$parent_pid == getmypid())
470+
{
471+
return false;
472+
}
470473

471474
return($this->child_bucket);
472475
}
@@ -479,7 +482,7 @@ public function child_bucket_get()
479482
*/
480483
public function add_bucket($bucket)
481484
{
482-
/* create the bucket by copying values from the default bucket */
485+
// create the bucket by copying values from the default bucket
483486
$this->max_children[$bucket] = $this->max_children[self::DEFAULT_BUCKET];
484487
$this->child_single_work_item[$bucket] = $this->child_single_work_item[self::DEFAULT_BUCKET];
485488
$this->max_work_per_child[$bucket] = $this->max_work_per_child[self::DEFAULT_BUCKET];
@@ -507,7 +510,7 @@ public function add_bucket($bucket)
507510
*/
508511
public function register_child_run($function_name, $bucket = self::DEFAULT_BUCKET)
509512
{
510-
/* call child function */
513+
// call child function
511514
if (is_callable($function_name) || ( is_array($function_name) && method_exists($function_name[0], $function_name[1]) ) || method_exists($this, $function_name) || function_exists($function_name) )
512515
{
513516
$this->child_function_run[$bucket] = $function_name;
@@ -538,7 +541,7 @@ public function register_parent_prefork($function_names)
538541
*/
539542
public function register_parent_fork($function_name, $bucket = self::DEFAULT_BUCKET)
540543
{
541-
/* call child function */
544+
// call child function
542545
if ( is_callable($function_name) || ( is_array($function_name) && method_exists($function_name[0], $function_name[1]) ) || method_exists($this, $function_name) || function_exists($function_name) )
543546
{
544547
$this->parent_function_fork[$bucket] = $function_name;
@@ -558,7 +561,7 @@ public function register_parent_fork($function_name, $bucket = self::DEFAULT_BUC
558561
*/
559562
public function register_parent_sighup($function_name, $cascade_signal = true)
560563
{
561-
/* call child function */
564+
// call child function
562565
if ( is_callable($function_name) || ( is_array($function_name) && method_exists($function_name[0], $function_name[1]) ) || method_exists($this, $function_name) || function_exists($function_name) )
563566
{
564567
$this->parent_function_sighup = $function_name;
@@ -578,7 +581,7 @@ public function register_parent_sighup($function_name, $cascade_signal = true)
578581
*/
579582
public function register_child_sighup($function_name, $bucket = self::DEFAULT_BUCKET)
580583
{
581-
/* call child function */
584+
// call child function
582585
if ( is_callable($function_name) || ( is_array($function_name) && method_exists($function_name[0], $function_name[1]) ) || method_exists($this, $function_name) || function_exists($function_name) )
583586
{
584587
$this->child_function_sighup[$bucket] = $function_name;
@@ -597,7 +600,7 @@ public function register_child_sighup($function_name, $bucket = self::DEFAULT_BU
597600
*/
598601
public function register_child_exit($function_name, $bucket = self::DEFAULT_BUCKET)
599602
{
600-
/* call child function */
603+
// call child function
601604
if ( is_callable($function_name) || ( is_array($function_name) && method_exists($function_name[0], $function_name[1]) ) || method_exists($this, $function_name) || function_exists($function_name) )
602605
{
603606
$this->child_function_exit[$bucket] = $function_name;
@@ -616,7 +619,7 @@ public function register_child_exit($function_name, $bucket = self::DEFAULT_BUCK
616619
*/
617620
public function register_child_timeout($function_name, $bucket = self::DEFAULT_BUCKET)
618621
{
619-
/* call child function */
622+
// call child function
620623
if ( is_callable($function_name) || ( is_array($function_name) && method_exists($function_name[0], $function_name[1]) ) || method_exists($this, $function_name) || function_exists($function_name) )
621624
{
622625
$this->child_function_timeout[$bucket] = $function_name;
@@ -653,7 +656,7 @@ public function register_parent_exit($function_name)
653656
*/
654657
public function register_parent_child_exit($function_name, $bucket = self::DEFAULT_BUCKET)
655658
{
656-
/* call parent function */
659+
// call parent function
657660
if ( is_callable($function_name) || ( is_array($function_name) && method_exists($function_name[0], $function_name[1]) ) || method_exists($this, $function_name) || function_exists($function_name) )
658661
{
659662
$this->parent_function_child_exited[$bucket] = $function_name;
@@ -690,7 +693,7 @@ public function register_parent_results($function_name, $bucket = self::DEFAULT_
690693
*/
691694
public function register_logging($function_name, $severity)
692695
{
693-
/* call parent function */
696+
// call parent function
694697
if ( is_callable($function_name) || ( is_array($function_name) && method_exists($function_name[0], $function_name[1]) ) || method_exists($this, $function_name) || function_exists($function_name) )
695698
{
696699
$this->log_function[$severity] = $function_name;
@@ -708,10 +711,10 @@ public function register_logging($function_name, $severity)
708711
*/
709712
public function __construct()
710713
{
711-
/* record pid of parent process */
714+
// record pid of parent process
712715
self::$parent_pid = getmypid();
713716

714-
/* install signal handlers */
717+
// install signal handlers
715718
declare(ticks = 1);
716719
pcntl_signal(SIGHUP, array(&$this, 'signal_handler_sighup'));
717720
pcntl_signal(SIGCHLD, array(&$this, 'signal_handler_sigchild'));
@@ -728,7 +731,7 @@ public function __construct()
728731
pcntl_signal(SIGTRAP, SIG_IGN);
729732
pcntl_signal(SIGSYS, SIG_IGN);
730733

731-
/* add barracuda specific prefork functions (doesn't hurt anything) */
734+
// add barracuda specific prefork functions (doesn't hurt anything)
732735
$this->parent_function_prefork = array('db_clear_connection_cache', 'memcache_clear_connection_cache');
733736
}
734737

@@ -770,12 +773,15 @@ public function signal_handler_sighup($signal_number)
770773
else
771774
{
772775
// child received sighup. note a child is only in one bucket, do not loop through all buckets
773-
$this->log('child process [' . getmypid() . '] received 9E7A sighup with bucket type [' . $this->child_bucket . ']', self::LOG_LEVEL_DEBUG);
774-
$this->invoke_callback(
775-
$this->child_function_sighup[$this->child_bucket],
776-
array($this->child_bucket),
777-
true
778-
);
776+
if (isset($this->child_bucket))
777+
{
778+
$this->log('child process [' . getmypid() . '] received sighup with bucket type [' . $this->child_bucket . ']', self::LOG_LEVEL_DEBUG);
779+
$this->invoke_callback(
780+
$this->child_function_sighup[$this->child_bucket],
781+
array($this->child_bucket),
782+
true
783+
);
784+
}
779785
}
780786
}
781787

@@ -911,7 +917,9 @@ public function signal_handler_sigint($signal_number)
911917
{
912918
// invoke child cleanup callback
913919
if (isset($this->child_bucket))
920+
{
914921
$this->invoke_callback($this->child_function_exit[$this->child_bucket], $parameters = array($this->child_bucket), true);
922+
}
915923
}
916924

917925
exit 378F (-1);

0 commit comments

Comments
 (0)
0