client = new FCGI\Client(); } public LoggerInterface $logger; public function getLogger(): LoggerInterface { return $this->logger; } public function setLogger(LoggerInterface $logger): void { $this->logger = $logger; } protected FCGI\Client $client; protected FCGI\Interfaces\ConfiguresSocketConnection $socket; public function connect(): self { $this->socket = new FCGI\SocketConnections\NetworkSocket($this->hostname, $this->port, $this->connectionTimeout, $this->readTimeout); return $this; } protected array $socketIds = []; /** * @throws FastCGIException */ public function sendRequest(FCGI\Interfaces\ProvidesRequestData $request): self { if (!isset($this->socket)) { $this->connect(); } try { $this->socketIds []= $this->client->sendAsyncRequest($this->socket, $request); } catch (FCGI\Exceptions\FastCGIClientException $exception) { $this->logger->error($exception->getMessage()); throw new FastCGIException($exception); } return $this; } /** * @return array */ public function awaitResponses(): array { $responses = []; while ($this->client->hasUnhandledResponses()) { try { $readyResponses = $this->client->readReadyResponses(3000); } catch (FCGI\Exceptions\FastCGIClientException $exception) { $this->logger->error($exception->getMessage()); continue; } foreach ($readyResponses as $response) { $responses []= $response; } } return $responses; } /** * @param string $uri * @return FastCGI * @throws FastCGIException */ public function get(string $uri): self { $request = new FCGI\Requests\GetRequest($this->documentRoot, ''); $request->setRequestUri($uri); return $this->sendRequest($request); } /** * @param string $uri * @param ?array $data * @return FastCGI * @throws FastCGIException */ public function post(string $uri, ?array $data): self { $content = new FCGI\RequestContents\JsonData($data ?? []); $request = FCGI\Requests\PostRequest::newWithRequestContent($this->documentRoot, $content); $request->setRequestUri($uri); return $this->sendRequest($request); } }