获取站点状态 - 向上或向下 [英] Get the site status - up or down

查看:24
本文介绍了获取站点状态 - 向上或向下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php
$host = 'http://google.com';
if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) {
echo 'online!';
fclose($socket);
} else {
echo 'offline.';
?>

我正在使用上述程序来获取站点的状态.但我总是收到离线消息.代码有问题吗?

I'm using the above program to get the status of site. But I always get an offline message. Is there any mistake with the code?

推荐答案

主机名不包含 http://,这只是一个 URI 的方案.

The hostname does not contain http://, that is only the scheme for an URI.

删除它并尝试这个:

<?php
$host = 'google.com';
if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) {
echo 'online!';
fclose($socket);
} else {
echo 'offline.';
}
?>

这篇关于获取站点状态 - 向上或向下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆