Skip to content

Commit 43c61ca

Browse files
committed
srand mt_srand
1 parent 2042dd9 commit 43c61ca

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Process.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,24 +166,27 @@ protected function setProcName()
166166

167167
protected function run()
168168
{
169+
srand();
170+
mt_srand();
171+
169172
register_shutdown_function([$this, 'handleFatalError']);
170173

171174
try {
172-
$this->log("[worker:{$this->id} {$this->workerPid}] process started");
175+
$this->log("process started");
173176
// Run job.
174177
call_user_func($this->job, $this);
175178
} catch (\Exception $e) {
176-
$this->log("[worker:{$this->id} {$this->workerPid}] $e");
179+
$this->log($e);
177180
exit(250);
178181
} catch (\Throwable $e) {
179-
$this->log("[worker:{$this->id} {$this->workerPid}] $e");
182+
$this->log($e);
180183
exit(250);
181184
}
182185
}
183186

184187
public function handleFatalError()
185188
{
186-
$errmsg = "[worker:{$this->id} {$this->workerPid}] process terminated";
189+
$errmsg = "process terminated";
187190
// Handle last error.
188191
$error = error_get_last();
189192
if ($error) {
@@ -197,7 +200,10 @@ public function log($contents)
197200
{
198201
$time = gettimeofday();
199202
$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);
203+
204+
$workerInfo = static::$isMaster ? '' : "[worker:{$this->id} {$this->workerPid}] ";
205+
$contents = sprintf("[%s.%s] [master %s] %s%s\n", date('Y-m-d H:i:s', $time['sec']), $usec, $this->masterPid, $workerInfo, $contents);
206+
201207
if (!$this->daemonize) {
202208
echo $contents;
203209
}
@@ -243,7 +249,7 @@ public function signalShutdownHandler($signo)
243249
posix_kill($workerPid, $signo);
244250
}
245251
} else {
246-
$this->log("[worker:{$this->id} {$this->workerPid}] " . $msg);
252+
$this->log($msg);
247253

248254
// Worker process exit.
249255
exit(0);

0 commit comments

Comments
 (0)