Skip to content

Commit 4d3a380

Browse files
committed
记录进程启动的日志
1 parent c67c1c9 commit 4d3a380

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Process.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ public function start()
4545
$this->masterPid = posix_getpid();
4646
$this->setProcName();
4747

48+
$this->log("\"{$this->name}\" started");
49+
4850
for ($id = 1; $id <= $this->count; $id++) {
4951
$this->forkWorker($id);
5052
}
5153

5254
$this->waitAll();
55+
56+
$this->log("\"{$this->name}\" stopped");
5357
}
5458

5559
protected function forkWorker($id)
@@ -65,8 +69,6 @@ protected function forkWorker($id)
6569

6670
$this->setProcName();
6771

68-
register_shutdown_function([$this, 'handleShutdown']);
69-
7072
// Run worker.
7173
$this->run();
7274
exit(0);
@@ -134,7 +136,7 @@ protected function waitAll()
134136
if ($id === false) {
135137
continue;
136138
}
137-
$this->log("[worker:$id $pid] exited with status $status");
139+
$this->log("[worker:$id $pid] process stopped with status $status");
138140
unset(static::$workers[$id]);
139141

140142
// refork
@@ -143,8 +145,6 @@ protected function waitAll()
143145
}
144146
}
145147
}
146-
147-
$this->log("\"{$this->name}\" stopped");
148148
}
149149

150150
protected function setProcName()
@@ -160,7 +160,10 @@ protected function setProcName()
160160

161161
protected function run()
162162
{
163+
register_shutdown_function([$this, 'handleShutdown']);
164+
163165
try {
166+
$this->log("[worker:{$this->id} {$this->workerPid}] process started");
164167
// Run job.
165168
call_user_func($this->job, $this);
166169
} catch (\Throwable $e) {

0 commit comments

Comments
 (0)