Skip to content

Instantly share code, notes, and snippets.

@raamdev
Created May 27, 2016 15:44
Show Gist options
  • Save raamdev/3bed98ef60ddfa947f24d59a063e2ecc to your computer and use it in GitHub Desktop.
Save raamdev/3bed98ef60ddfa947f24d59a063e2ecc to your computer and use it in GitHub Desktop.
<?php
$curl_localhost_test_success = FALSE;
$curl_localhost_test_url = 'http://'.$_SERVER['HTTP_HOST'];
$curl_localhost_test_url_return_string_frag = 'html';
if(is_resource($_curl_test_resource = curl_init()))
{
curl_setopt_array(
$_curl_test_resource, array(
CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 5,
CURLOPT_URL => $curl_localhost_test_url, CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_FAILONERROR => TRUE, CURLOPT_FORBID_REUSE => TRUE, CURLOPT_SSL_VERIFYPEER => TRUE
)
);
if(stripos((string)curl_exec($_curl_test_resource), $curl_localhost_test_url_return_string_frag) !== FALSE)
$curl_localhost_test_success = TRUE;
curl_close($_curl_test_resource);
}
if(!$curl_localhost_test_success) {
echo "cURL failed to connect to ". $curl_localhost_test_url;
} else {
echo "cURL successfully connected to ". $curl_localhost_test_url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment