Getting HTTP code in PHP using curl

后端 未结 9 2089
无人共我
无人共我 2020-11-28 03:43

I\'m using CURL to get the status of a site, if it\'s up/down or redirecting to another site. I want to get it as streamlined as possible, but it\'s not working well.

<
9条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 04:16

    Here is my solution need get Status Http for checking status of server regularly

    $url = 'http://www.example.com'; // Your server link
    
    while(true) {
    
        $strHeader = get_headers($url)[0];
    
        $statusCode = substr($strHeader, 9, 3 );
    
        if($statusCode != 200 ) {
            echo 'Server down.';
            // Send email 
        }
        else {
            echo 'oK';
        }
    
        sleep(30);
    }
    

提交回复
热议问题