Skip to content

Commit 40489d6

Browse files
committed
捕获程序异常后自动重新执行,保持进程不退出
1 parent d4dd3df commit 40489d6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Process.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public function start()
5454

5555
$this->setProcName();
5656

57+
register_shutdown_function([$this, 'handleShutdown']);
58+
5759
// Run worker.
5860
$this->run();
5961
exit(0);
@@ -144,13 +146,13 @@ protected function setProcName()
144146

145147
protected function run()
146148
{
147-
register_shutdown_function([$this, 'handleShutdown']);
148-
149149
try {
150150
// Run job.
151151
call_user_func($this->job, $this);
152152
} catch (\Throwable $e) {
153153
$this->log('[worker '. posix_getpid() .'] ' . $e);
154+
// rerun
155+
$this->run();
154156
}
155157
}
156158

0 commit comments

Comments
 (0)