mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-01 19:00:20 +02:00
ProcessHandler: Make timeout of stream_select()
configurable (#1916)
Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>
This commit is contained in:
@@ -43,6 +43,8 @@ class ProcessHandler extends AbstractProcessingHandler
|
||||
*/
|
||||
private array $pipes = [];
|
||||
|
||||
private float $timeout;
|
||||
|
||||
/**
|
||||
* @var array<int, string[]>
|
||||
*/
|
||||
@@ -56,9 +58,10 @@ class ProcessHandler extends AbstractProcessingHandler
|
||||
* @param string $command Command for the process to start. Absolute paths are recommended,
|
||||
* especially if you do not use the $cwd parameter.
|
||||
* @param string|null $cwd "Current working directory" (CWD) for the process to be executed in.
|
||||
* @param float $timeout The maximum timeout (in seconds) for the stream_select() function.
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(string $command, int|string|Level $level = Level::Debug, bool $bubble = true, ?string $cwd = null)
|
||||
public function __construct(string $command, int|string|Level $level = Level::Debug, bool $bubble = true, ?string $cwd = null, float $timeout = 1.0)
|
||||
{
|
||||
if ($command === '') {
|
||||
throw new \InvalidArgumentException('The command argument must be a non-empty string.');
|
||||
@@ -71,6 +74,7 @@ class ProcessHandler extends AbstractProcessingHandler
|
||||
|
||||
$this->command = $command;
|
||||
$this->cwd = $cwd;
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +150,8 @@ class ProcessHandler extends AbstractProcessingHandler
|
||||
$empty = [];
|
||||
$errorPipes = [$this->pipes[2]];
|
||||
|
||||
return stream_select($errorPipes, $empty, $empty, 1);
|
||||
$seconds = (int) $this->timeout;
|
||||
return stream_select($errorPipes, $empty, $empty, $seconds, (int) (($this->timeout - $seconds) * 1000000));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user