/** * @param Request $request * * @return Response * @throws GearmanConnectionException */ public function send(Request $request) { if (false === $this->isConnected()) { throw new GearmanConnectionException('No connection established.'); } $isWritten = fwrite($this->connection, $request->getCommand(), $request->getLength()); if (false === $isWritten) { throw new GearmanConnectionException('Cant send command!'); } $response = new Response(); while (!feof($this->connection)) { $line = trim(fgets($this->connection)); if ($line === '.') { break; } $response->addLine($line); } return $response; }