From 4546ef8b1dff8fb291014c046f4839e799582983 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Sat, 17 Jun 2017 20:46:22 +0200 Subject: [PATCH] Skip cli_set_process_title inside phpdbg --- bin/worker | 11 +++++++---- lib/Sync/ChannelParser.php | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bin/worker b/bin/worker index 8a97f00b..1b6184e9 100644 --- a/bin/worker +++ b/bin/worker @@ -4,7 +4,10 @@ use Amp\Parallel\Sync; use Amp\Parallel\Worker; -@cli_set_process_title('amp-worker'); +// Doesn't exist in phpdbg... +if (\function_exists('cli_set_process_title')) { + @cli_set_process_title('amp-worker'); +} // Redirect all output written using echo, print, printf, etc. to STDERR. ob_start(function ($data) { @@ -17,7 +20,7 @@ ob_start(function ($data) { dirname(__DIR__, 3) . '/autoload.php', dirname(__DIR__) . '/vendor/autoload.php', ]; - + $autoloadPath = null; foreach ($paths as $path) { if (file_exists($path)) { @@ -25,12 +28,12 @@ ob_start(function ($data) { break; } } - + if ($autoloadPath === null) { fwrite(STDERR, 'Could not locate autoload.php.'); exit(1); } - + require $autoloadPath; })(); diff --git a/lib/Sync/ChannelParser.php b/lib/Sync/ChannelParser.php index 40927f25..16a781e6 100644 --- a/lib/Sync/ChannelParser.php +++ b/lib/Sync/ChannelParser.php @@ -46,10 +46,11 @@ public function encode($data): string { */ private static function parser(callable $callback, callable $errorHandler): \Generator { while (true) { - $data = \unpack("Cprefix/Llength", yield self::HEADER_LENGTH); + $header = yield self::HEADER_LENGTH; + $data = \unpack("Cprefix/Llength", $header); if ($data["prefix"] !== 0) { - throw new ChannelException("Invalid header received"); + throw new ChannelException("Invalid header received: " . \bin2hex($header)); } $data = yield $data["length"];