Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 4d9dc01

Browse files
authored
Update ServerProcessInspector.php
1 parent 69198c5 commit 4d9dc01

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Workerman/ServerProcessInspector.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@ public function serverIsRunning(): bool
2626
return (bool) $masterProcessId;
2727
}
2828

29-
public function writeProcessId($pid)
29+
public function writeProcessId()
3030
{
31-
$this->serverStateFile->writeProcessId($pid);
31+
$pid = @file_get_contents(config('workerman.http.pidFile'));
32+
33+
if ($pid) {
34+
$this->serverStateFile->writeProcessId($pid);
35+
return true;
36+
}
37+
38+
return false;
3239
}
3340

3441
public function getServer($mode, array $args = [])
@@ -74,6 +81,8 @@ public function startServer()
7481

7582
$server->start();
7683

84+
$server->waitUntil([$this, 'writeProcessId']);
85+
7786
$this->writeProcessId($server->getPid());
7887

7988
return $server;
@@ -90,13 +99,11 @@ public function startDaemonServer()
9099
return;
91100
}
92101

93-
$server = $this->getServer('start');
94-
95-
$server->run();
102+
$server = $this->getServer('start', ['-d']);
96103

97-
$pid = file_get_contents(config('workerman.gatewayworker.http.pid_file'));
104+
$server->start();
98105

99-
$this->writeProcessId($pid);
106+
$server->waitUntil([$this, 'writeProcessId']);
100107

101108
return $server;
102109
}

0 commit comments

Comments
 (0)