Copy the code The code is as follows:
$url = 'http://www.baidu.com';
$ch = curl_init();
$timeout = 10;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
if (false == $contents)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
….
}
to copy the code code As follows:
curl_getinfo($ch, CURLINFO_HTTP_CODE);
The above introduces the code to determine whether the URL is valid under PHP when the telecommunications network is disconnected, including the content of the telecommunications network disconnection. I hope it will be helpful to friends who are interested in PHP tutorials.