diff options
Diffstat (limited to 'src/Worker.php')
-rw-r--r-- | src/Worker.php | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/Worker.php b/src/Worker.php index d9de0fa9..2da16e86 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -11,6 +11,8 @@ namespace Spiral\RoadRunner; use Spiral\Goridge\Exceptions\GoridgeException; use Spiral\Goridge\RelayInterface as Relay; +use Spiral\Goridge\SocketRelay; +use Spiral\Goridge\StreamRelay; use Spiral\RoadRunner\Exception\RoadRunnerException; /** @@ -28,15 +30,19 @@ class Worker // Send as response context to request worker termination public const STOP = '{"stop":true}'; - /** @var Relay */ + /** @var Relay|StreamRelay|SocketRelay */ private $relay; + /** @var bool */ + private $optimizedRelay; + /** * @param Relay $relay */ public function __construct(Relay $relay) { $this->relay = $relay; + $this->optimizedRelay = method_exists($relay, 'sendPackage'); } /** @@ -83,12 +89,22 @@ class Worker */ public function send(string $payload = null, string $header = null): void { - $this->relay->sendPackage( - (string)$header, - Relay::PAYLOAD_CONTROL | ($header === null ? Relay::PAYLOAD_NONE : Relay::PAYLOAD_RAW), - (string)$payload, - Relay::PAYLOAD_RAW - ); + if (!$this->optimizedRelay) { + if ($header === null) { + $this->relay->send('', Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_NONE); + } else { + $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW); + } + + $this->relay->send((string)$payload, Relay::PAYLOAD_RAW); + } else { + $this->relay->sendPackage( + (string)$header, + Relay::PAYLOAD_CONTROL | ($header === null ? Relay::PAYLOAD_NONE : Relay::PAYLOAD_RAW), + (string)$payload, + Relay::PAYLOAD_RAW + ); + } } /** |