🔧
This commit is contained in:
@@ -30,6 +30,7 @@ abstract class AbstractStream
|
||||
protected $in;
|
||||
/** @var resource|null */
|
||||
protected $out;
|
||||
protected $err;
|
||||
|
||||
private string $debug = '';
|
||||
|
||||
@@ -68,7 +69,7 @@ abstract class AbstractStream
|
||||
|
||||
public function terminate(): void
|
||||
{
|
||||
$this->stream = $this->out = $this->in = null;
|
||||
$this->stream = $this->err = $this->out = $this->in = null;
|
||||
}
|
||||
|
||||
public function readLine(): string
|
||||
@@ -77,15 +78,17 @@ abstract class AbstractStream
|
||||
return '';
|
||||
}
|
||||
|
||||
$line = fgets($this->out);
|
||||
$line = @fgets($this->out);
|
||||
if ('' === $line || false === $line) {
|
||||
$metas = stream_get_meta_data($this->out);
|
||||
if ($metas['timed_out']) {
|
||||
if (stream_get_meta_data($this->out)['timed_out']) {
|
||||
throw new TransportException(sprintf('Connection to "%s" timed out.', $this->getReadConnectionDescription()));
|
||||
}
|
||||
if ($metas['eof']) {
|
||||
if (feof($this->out)) { // don't use "eof" metadata, it's not accurate on Windows
|
||||
throw new TransportException(sprintf('Connection to "%s" has been closed unexpectedly.', $this->getReadConnectionDescription()));
|
||||
}
|
||||
if (false === $line) {
|
||||
throw new TransportException(sprintf('Unable to read from connection to "%s": ', $this->getReadConnectionDescription().error_get_last()['message'] ?? ''));
|
||||
}
|
||||
}
|
||||
|
||||
$this->debug .= sprintf('< %s', $line);
|
||||
|
||||
@@ -24,12 +24,18 @@ use Symfony\Component\Mailer\Exception\TransportException;
|
||||
final class ProcessStream extends AbstractStream
|
||||
{
|
||||
private string $command;
|
||||
private bool $interactive = false;
|
||||
|
||||
public function setCommand(string $command): void
|
||||
{
|
||||
$this->command = $command;
|
||||
}
|
||||
|
||||
public function setInteractive(bool $interactive): void
|
||||
{
|
||||
$this->interactive = $interactive;
|
||||
}
|
||||
|
||||
public function initialize(): void
|
||||
{
|
||||
$descriptorSpec = [
|
||||
@@ -45,17 +51,27 @@ final class ProcessStream extends AbstractStream
|
||||
}
|
||||
$this->in = &$pipes[0];
|
||||
$this->out = &$pipes[1];
|
||||
$this->err = &$pipes[2];
|
||||
}
|
||||
|
||||
public function terminate(): void
|
||||
{
|
||||
if (null !== $this->stream) {
|
||||
fclose($this->in);
|
||||
$out = stream_get_contents($this->out);
|
||||
fclose($this->out);
|
||||
proc_close($this->stream);
|
||||
$err = stream_get_contents($this->err);
|
||||
fclose($this->err);
|
||||
if (0 !== $exitCode = proc_close($this->stream)) {
|
||||
$errorMessage = 'Process failed with exit code '.$exitCode.': '.$out.$err;
|
||||
}
|
||||
}
|
||||
|
||||
parent::terminate();
|
||||
|
||||
if (!$this->interactive && isset($errorMessage)) {
|
||||
throw new TransportException($errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getReadConnectionDescription(): string
|
||||
|
||||
@@ -160,7 +160,7 @@ final class SocketStream extends AbstractStream
|
||||
}
|
||||
|
||||
stream_set_blocking($this->stream, true);
|
||||
stream_set_timeout($this->stream, $timeout);
|
||||
stream_set_timeout($this->stream, (int) $timeout, (int) (($timeout - (int) $timeout) * 1000000));
|
||||
$this->in = &$this->stream;
|
||||
$this->out = &$this->stream;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user