简体   繁体   English

如果网站启动,如何检查php / html?

[英]How to check from php/html if website is up?

I want the users of my website to check if any other website (http and/or https) is up. 我希望我的网站用户检查是否有其他网站(http和/或https)。 There are sites out there that use google analytics for that (if I understood it right). 有些网站使用谷歌分析(如果我理解的话)。 But I don't understand how they do it. 但我不明白他们是怎么做到的。

Question 1) How do I use google-analytics on my website to check if some other site is up? 问题1)如何在我的网站上使用谷歌分析检查是否有其他网站?

Question 2 ) How do I do it by myself? 问题2 )我如何自己做? Using php or javascript? 使用PHP或JavaScript? I wonder if google-analytics might be more reliable in terms if they use multiple server locations to check whether the site is online compared to a single location that I would use with my own code. 我想知道,如果google-analytics使用多个服务器位置检查网站是否在线,而不是我将使用自己的代码的单个位置,那么它是否可能更可靠。

您可以使用服务器端Curl并监视http响应标头,站点超时。

One can try to connect directly to the http(s) port of the server. 可以尝试直接连接到服务器的http(s)端口。

    $canConnect = FALSE;
    $host = 'www.example.com';
    $service_port = 80; // http, for https use 443;
    $address = gethostbyname ($host);
    $socket = socket_create (AF_INET, SOCK_STREAM, SOL_TCP);
    if ($socket !== FALSE) {
        $result = socket_connect ($socket, $address, $service_port);
        if ($result) {
            $canConnect = TRUE;
        }
        socket_close($socket);
    }

You could ping the servers and monitor the responses. 您可以ping服务器并监视响应。 This link shows you the implementation in PHP: http://www.darian-brown.com/php-ping-script-to-check-remote-server-or-website/ 此链接显示了PHP中的实现: http//www.darian-brown.com/php-ping-script-to-check-remote-server-or-website/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM