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

2019-08-13 18:19发布

I want the users of my website to check if any other website (http and/or https) is up. 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?

Question 2) How do I do it by myself? Using php or 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.

3条回答
仙女界的扛把子
2楼-- · 2019-08-13 18:42

You can use server side Curl and monitor http response header, site timeouts.

查看更多
冷血范
3楼-- · 2019-08-13 18:43

You could ping the servers and monitor the responses. This link shows you the implementation in PHP: http://www.darian-brown.com/php-ping-script-to-check-remote-server-or-website/

查看更多
唯我独甜
4楼-- · 2019-08-13 18:45

One can try to connect directly to the http(s) port of the server.

    $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);
    }
查看更多
登录 后发表回答