/**
  * Check if the database can be contacted.
  *
  * @todo SPARQL endpoints sometimes return errors if no (valid) query
  * is posted. The current implementation tries to catch this, but this
  * might not be entirely correct. Especially, the SPARQL 1.1 HTTP error
  * codes for Update are not defined yet (April 15 2011).
  *
  * @param $pingQueryEndpoint boolean true if the query endpoint should be
  * pinged, false if the update endpoint should be pinged
  *
  * @return boolean to indicate success
  */
 public function ping($endpointType = self::EP_TYPE_QUERY)
 {
     if ($endpointType == self::EP_TYPE_QUERY) {
         $this->httpRequest->setOption(CURLOPT_URL, $this->repositoryClient->getQueryEndpoint());
         $this->httpRequest->setOption(CURLOPT_NOBODY, true);
         $this->httpRequest->setOption(CURLOPT_POST, true);
     } elseif ($endpointType == self::EP_TYPE_UPDATE) {
         if ($this->repositoryClient->getUpdateEndpoint() === '') {
             return false;
         }
         $this->httpRequest->setOption(CURLOPT_URL, $this->repositoryClient->getUpdateEndpoint());
         $this->httpRequest->setOption(CURLOPT_NOBODY, false);
         // 4Store gives 404 instead of 500 with CURLOPT_NOBODY
     } else {
         // ( $endpointType == self::EP_TYPE_DATA )
         if ($this->repositoryClient->getDataEndpoint() === '') {
             return false;
         }
         // try an empty POST
         return $this->doHttpPost('');
     }
     $this->httpRequest->execute();
     if ($this->httpRequest->getLastErrorCode() == 0) {
         return true;
     }
     // valid HTTP responses from a complaining SPARQL endpoint that is alive and kicking
     $httpCode = $this->httpRequest->getLastTransferInfo(CURLINFO_HTTP_CODE);
     return $httpCode == 500 || $httpCode == 400;
 }
Пример #2
0
 /**
  * @since  1.0
  *
  * @param HttpRequest $httpRequest
  */
 public function __construct(HttpRequest $httpRequest)
 {
     $errorCode = $httpRequest->getLastErrorCode();
     switch ($errorCode) {
         case 22:
             //	equals CURLE_HTTP_RETURNED_ERROR but this constant is not defined in PHP
             $httpCode = $httpRequest->getLastTransferInfo(CURLINFO_HTTP_CODE);
             $message = "HTTP request ended with {$httpCode} code\n";
             break;
         default:
             $message = $httpRequest->getLastError();
     }
     parent::__construct($message, $errorCode);
 }