diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-21 17:25:24 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-21 17:25:24 +0000 |
commit | 34cb7f64880bfed566c0f2405faf068cbba3b736 (patch) | |
tree | 3d077bc417bb10411b96155aa4a702732a71e545 | |
parent | 540e0ec01382a23221f0e8e359e756b15c1216f7 (diff) | |
parent | 3b04f1655eab65b5037f15064549bd3abae527ea (diff) |
Merge #309
309: Reduce syscalls usage r=48d90782 a=48d90782
resolves #305
Co-authored-by: Valery Piashchynski <[email protected]>
Co-authored-by: Valentin V / vvval <[email protected]>
-rw-r--r-- | composer.json | 3 | ||||
-rw-r--r-- | src/Worker.php | 22 |
2 files changed, 21 insertions, 4 deletions
diff --git a/composer.json b/composer.json index aa461df3..fde54fa8 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,9 @@ ], "require": { "php": "^7.1", + "ext-json": "*", "ext-curl": "*", - "spiral/goridge": "^2.0", + "spiral/goridge": "^2.3", "psr/http-factory": "^1.0", "psr/http-message": "^1.0", "symfony/console": "^2.5.0 || ^3.0.0 || ^4.0.0 || ^5.0.0", diff --git a/src/Worker.php b/src/Worker.php index 35294221..74296801 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -66,7 +66,7 @@ class Worker } if ($flags & Relay::PAYLOAD_ERROR) { - return new \Error((string) $body); + return new \Error((string)$body); } return $body; @@ -89,7 +89,23 @@ class Worker $this->relay->send($header, Relay::PAYLOAD_CONTROL | Relay::PAYLOAD_RAW); } - $this->relay->send((string) $payload, Relay::PAYLOAD_RAW); + $this->relay->send((string)$payload, Relay::PAYLOAD_RAW); + } + + /** + * Respond to the server with result of task execution and execution context. Uses less amount of sys_calls. + * + * @param string|null $payload + * @param string|null $header + */ + public function sendPackage(string $payload = null, string $header = null): void + { + $this->relay->sendPackage( + (string)$header, + Relay::PAYLOAD_CONTROL | ($header ? Relay::PAYLOAD_NONE : Relay::PAYLOAD_RAW), + (string)$payload, + Relay::PAYLOAD_RAW + ); } /** @@ -137,7 +153,7 @@ class Worker private function handleControl(string $body = null, &$header = null, int $flags = 0): bool { $header = $body; - if (is_null($body) || $flags & Relay::PAYLOAD_RAW) { + if ($body === null || $flags & Relay::PAYLOAD_RAW) { // empty or raw prefix return true; } |