我要获取页面状态代码。
URL地址具有一个端口,并在该别名之后:
http://93.184.216.xxx:3000/status
我尝试过这个:
function status($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true); // we want headers
curl_setopt($ch, CURLOPT_NOBODY, true); // we don't need body
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpcode == 200) { return '<span class="green-link">ONLINE</span>';}
else {
return '<span class="red-link">'.$httpcode.'</span>';}
}
但这没用,我总是状态为0。
有人可以有更好的主意吗? 谢谢