peekMessageType($requestBody) === TMessageType::ONEWAY && function_exists('pcntl_fork') && $this->dispatchOnewayAsync($requestBody) ) { return; } $this->dispatchSync($requestBody); } private function peekMessageType(string $body): ?int { if ($body === '') { return null; } try { $type = null; $name = null; $seqid = null; $this->protocolFactory ->getProtocol(new TMemoryBuffer($body)) ->readMessageBegin($name, $type, $seqid); return $type; } catch (\Throwable) { return null; } } private function dispatchOnewayAsync(string $body): bool { header('Content-Length: 0'); $pid = pcntl_fork(); if ($pid > 0) { return true; } if ($pid === 0) { if (defined('STDIN')) { fclose(STDIN); } if (defined('STDOUT')) { fclose(STDOUT); } if (defined('STDERR')) { fclose(STDERR); } $this->processor->process( $this->protocolFactory->getProtocol(new TMemoryBuffer($body)), $this->protocolFactory->getProtocol(new TMemoryBuffer()), ); exit(0); } return false; } private function dispatchSync(string $body): void { $output = new TMemoryBuffer(); $this->processor->process( $this->protocolFactory->getProtocol(new TMemoryBuffer($body)), $this->protocolFactory->getProtocol($output), ); $responseBody = $output->getBuffer(); header('Content-Length: ' . strlen($responseBody)); echo $responseBody; } }