0xFFFF) { throw new \RuntimeException('Prefix is too long!'); } $sockets = []; foreach ([ $prefix."2", $prefix."1", ] as $k => $socket) { if (!\posix_mkfifo($socket, 0777)) { throw new \RuntimeException('Could not create FIFO client socket!'); } \register_shutdown_function(static function () use ($socket): void { @\unlink($socket); }); if (!$sockets[$k] = \fopen($socket, 'r+')) { // Open in r+w mode to prevent blocking if there is no reader throw new \RuntimeException("Could not open FIFO client socket"); } } if (!$tempSocket = \fopen($uri, 'r+')) { // Open in r+w mode to prevent blocking if there is no reader throw new \RuntimeException("Could not connect to FIFO server"); } \stream_set_blocking($tempSocket, false); \stream_set_write_buffer($tempSocket, 0); if (!\fwrite($tempSocket, \pack('v', \strlen($prefix)).$prefix)) { \fclose($tempSocket); unset($tempSocket); throw new \RuntimeException("Failure sending request to FIFO server"); } \fclose($tempSocket); unset($tempSocket); $socket = new ChannelledSocket( new ReadableResourceStream($sockets[0]), new WritableResourceStream($sockets[1]), ); try { $result = async($socket->receive(...))->await( $cancellation ? new CompositeCancellation( $cancellation, new TimeoutCancellation(0.5) ) : new TimeoutCancellation(0.5) ); if (!$result instanceof ChannelInitAck) { throw new \RuntimeException('Missing init ack!'); } return $socket; } catch (CancelledException $e) { if ($cancellation?->isRequested()) { throw $e; } } } while (true); throw new AssertionError("Unreachable!"); }