@@ -115,14 +115,14 @@ protected function setsid()
115115
116116 protected function redirectStd ()
117117 {
118+ $ logFile = $ this ->logFile ?: '/dev/null ' ;
119+
118120 // redirect stdin to /dev/null
119121 // redirect stdout, stderr to $logFile
120122 fclose (STDIN );
121123 fclose (STDOUT );
122124 fclose (STDERR );
123125
124- $ logFile = $ this ->logFile ?: '/dev/null ' ;
125-
126126 global $ stdin , $ stdout , $ stderr ;
127127 $ stdin = fopen ('/dev/null ' , 'r ' );
128128 $ stdout = fopen ($ logFile , 'a ' );
@@ -172,8 +172,11 @@ protected function run()
172172 $ this ->log ("[worker: {$ this ->id } {$ this ->workerPid }] process started " );
173173 // Run job.
174174 call_user_func ($ this ->job , $ this );
175+ } catch (\Exception $ e ) {
176+ $ this ->log ("[worker: {$ this ->id } {$ this ->workerPid }] $ e " );
177+ exit (250 );
175178 } catch (\Throwable $ e ) {
176- $ this ->log ("[worker: {$ this ->id } {$ this ->workerPid }] " . $ e );
179+ $ this ->log ("[worker: {$ this ->id } {$ this ->workerPid }] $ e " );
177180 exit (250 );
178181 }
179182 }
@@ -193,7 +196,8 @@ public function handleFatalError()
193196 public function log ($ contents )
194197 {
195198 $ time = gettimeofday ();
196- $ contents = sprintf ("[%s.%s] [master %s] %s \n" , date ('Y-m-d H:i:s ' , $ time ['sec ' ]), $ time ['usec ' ], $ this ->masterPid , $ contents );
199+ $ usec = str_pad ($ time ['usec ' ], 6 , '0 ' );
200+ $ contents = sprintf ("[%s.%s] [master %s] %s \n" , date ('Y-m-d H:i:s ' , $ time ['sec ' ]), $ usec , $ this ->masterPid , $ contents );
197201 if (!$ this ->daemonize ) {
198202 echo $ contents ;
199203 }
0 commit comments