@@ -128,6 +128,13 @@ abstract class Core_Daemon
128
128
'parent ' => true ,
129
129
);
130
130
131
+ /**
132
+ * Handle for log() method,
133
+ * @see Core_Daemon::log()
134
+ * @see Core_Daemon::restart();
135
+ * @var stream
136
+ */
137
+ private static $ log_handle = false ;
131
138
132
139
/**
133
140
* Implement this method to define plugins
@@ -615,8 +622,7 @@ public function task($task)
615
622
* @param string $label Truncated at 12 chars
616
623
*/
617
624
public function log ($ message , $ label = '' , $ indent = 0 )
618
- {
619
- static $ handle = false ;
625
+ {
620
626
static $ log_file = '' ;
621
627
static $ log_file_check_at = 0 ;
622
628
static $ log_file_error = false ;
@@ -630,14 +636,14 @@ public function log($message, $label = '', $indent = 0)
630
636
if (time () >= $ log_file_check_at && $ this ->log_file () != $ log_file ) {
631
637
$ log_file = $ this ->log_file ();
632
638
$ log_file_check_at = mktime (date ('H ' ), (date ('i ' ) - (date ('i ' ) % 5 )) + 5 , null );
633
- @fclose ($ handle );
634
- $ handle = $ log_file_error = false ;
639
+ @fclose (self :: $ log_handle );
640
+ self :: $ log_handle = $ log_file_error = false ;
635
641
}
636
642
637
- if ($ handle === false ) {
638
- if (strlen ($ log_file ) > 0 && $ handle = @fopen ($ log_file , 'a+ ' )) {
643
+ if (self :: $ log_handle === false ) {
644
+ if (strlen ($ log_file ) > 0 && self :: $ log_handle = @fopen ($ log_file , 'a+ ' )) {
639
645
if ($ this ->is ('parent ' )) {
640
- fwrite ($ handle , $ header );
646
+ fwrite (self :: $ log_handle , $ header );
641
647
if ($ this ->is ('stdout ' ))
642
648
echo $ header ;
643
649
}
@@ -649,8 +655,8 @@ public function log($message, $label = '', $indent = 0)
649
655
650
656
$ message = $ prefix . ' ' . str_replace ("\n" , "\n$ prefix " , trim ($ message )) . "\n" ;
651
657
652
- if ($ handle )
653
- fwrite ($ handle , $ message );
658
+ if (self :: $ log_handle )
659
+ fwrite (self :: $ log_handle , $ message );
654
660
655
661
if ($ this ->is ('stdout ' ))
656
662
echo $ message ;
@@ -927,6 +933,8 @@ public function restart()
927
933
if (is_resource (STDOUT )) fclose (STDOUT );
928
934
if (is_resource (STDERR )) fclose (STDERR );
929
935
if (is_resource (STDIN )) fclose (STDIN );
936
+ // Close the static log handle to prevent it being inherrited by the new process.
937
+ if (is_resource (self ::$ log_handle )) fclose (self ::$ log_handle );
930
938
exec ($ this ->command ());
931
939
932
940
// A new daemon process has been created. This one will stick around just long enough to clean up the worker processes.
0 commit comments