Пример #1
0
 /**
  * Check the URL disponibility
  *
  * @param String   $url         URL site
  * @param String[] $option      Option array
  * @param Boolean  $return_body Return the content of the page
  *
  * @return bool|int
  */
 static function checkUrl($url, $option = null, $return_body = false)
 {
     try {
         $http_client = new CHTTPClient($url);
         if ($option) {
             if (CMbArray::get($option, "ca_cert")) {
                 $http_client->setSSLPeer($option["ca_cert"]);
             }
             if (CMbArray::get($option, "username") || CMbArray::get($option, "password")) {
                 $http_client->setHTTPAuthentification($option["username"], $option["password"]);
             }
             if (CMbArray::get($option, "local_cert")) {
                 $http_client->setSSLAuthentification($option["local_cert"], $option["passphrase"]);
             }
         }
         $http_client->setOption(CURLOPT_HEADER, true);
         $result = $http_client->get();
     } catch (Exception $e) {
         return false;
     }
     if ($return_body) {
         return $result;
     }
     return preg_match("|200|", $result);
 }