Example #1
0
 /**
  * Write the connection header
  * @param $endpoint
  * @param Request\TrackingRequest $request
  * @param bool $lastData
  * @return string
  * @throws Exception\EndpointServerException
  */
 private function writeHeader($endpoint, Request\TrackingRequest $request, $lastData = false)
 {
     // create data
     $payloadString = http_build_query($request->getPayload());
     $payloadLength = strlen($payloadString);
     $header = 'POST ' . $endpoint['path'] . ' HTTP/1.1' . "\r\n" . 'Host: ' . $endpoint['host'] . "\r\n" . 'User-Agent: Google-Measurement-PHP-Client' . "\r\n" . 'Content-Length: ' . $payloadLength . "\r\n" . ($lastData ? 'Connection: Close' . "\r\n" : '') . "\r\n";
     // fwrite + check if fwrite was ok
     if (!fwrite($this->connection, $header) || !fwrite($this->connection, $payloadString)) {
         throw new Exception\EndpointServerException('Server closed connection unexpectedly');
     }
     return $header;
 }