/**
  * Check for errors and fix headers of a request based on a curl response
  *
  * @param RequestInterface $request Request to process
  * @param CurlHandle $handle Curl handle object
  * @param array $curl Curl message returned from curl_multi_info_read
  *
  * @throws CurlException on Curl error
  */
 protected function processResponse(RequestInterface $request, CurlHandle $handle, array $curl)
 {
     // Set the transfer stats on the response
     $handle->updateRequestFromTransfer($request);
     // Check if a cURL exception occurred, and if so, notify things
     $e = $this->isCurlException($request, $handle, $curl);
     // Always remove completed curl handles.  They can be added back again
     // via events if needed (e.g. ExponentialBackoffPlugin)
     $this->removeHandle($request);
     if ($e) {
         // Set the state of the request to an error
         $request->setState(RequestInterface::STATE_ERROR);
         // Notify things that listen to the request of the failure
         $request->dispatch('request.exception', array('request' => $this, 'exception' => $e));
         // Allow things to ignore the error if possible
         if ($request->getState() != RequestInterface::STATE_TRANSFER) {
             $this->remove($request);
             throw $e;
         }
     } else {
         $request->setState(RequestInterface::STATE_COMPLETE);
         // Allow things to ignore the error if possible
         if ($request->getState() != RequestInterface::STATE_TRANSFER) {
             $this->remove($request);
         }
     }
 }
예제 #2
0
 /**
  * Check for errors and fix headers of a request based on a curl response
  *
  * @param RequestInterface $request Request to process
  * @param CurlHandle       $handle  Curl handle object
  * @param array            $curl    Array returned from curl_multi_info_read
  *
  * @throws CurlException on Curl error
  */
 protected function processResponse(RequestInterface $request, CurlHandle $handle, array $curl)
 {
     // Set the transfer stats on the response
     $handle->updateRequestFromTransfer($request);
     // Check if a cURL exception occurred, and if so, notify things
     $curlException = $this->isCurlException($request, $handle, $curl);
     // Always remove completed curl handles.  They can be added back again
     // via events if needed (e.g. ExponentialBackoffPlugin)
     $this->removeHandle($request);
     if (!$curlException) {
         if ($this->validateResponseWasSet($request)) {
             $state = $request->setState(RequestInterface::STATE_COMPLETE, array('handle' => $handle));
             // Only remove the request if it wasn't resent as a result of
             // the state change
             if ($state != RequestInterface::STATE_TRANSFER) {
                 $this->remove($request);
             }
         }
         return;
     }
     // Set the state of the request to an error
     $state = $request->setState(RequestInterface::STATE_ERROR, array('exception' => $curlException));
     // Allow things to ignore the error if possible
     if ($state != RequestInterface::STATE_TRANSFER) {
         $this->remove($request);
     }
     // The error was not handled, so fail
     if ($state == RequestInterface::STATE_ERROR) {
         /** @var CurlException $curlException */
         throw $curlException;
     }
 }
예제 #3
0
protected function processResponse(RequestInterface $request, CurlHandle $handle, array $curl)
{

 $handle->updateRequestFromTransfer($request);

 $curlException = $this->isCurlException($request, $handle, $curl);


 
 $this->removeHandle($request);

if (!$curlException) {
$state = $request->setState(RequestInterface::STATE_COMPLETE, array('handle' => $handle));

 if ($state != RequestInterface::STATE_TRANSFER) {
$this->remove($request);
}
} else {

 $state = $request->setState(RequestInterface::STATE_ERROR, array('exception' => $curlException));

 if ($state != RequestInterface::STATE_TRANSFER) {
$this->remove($request);
}

 if ($state == RequestInterface::STATE_ERROR) {

throw $curlException;
}
}
}