curl and ping - how to check whether a website is either up or down?

后端 未结 7 2164
再見小時候
再見小時候 2020-11-28 12:51

I want to check whether a website is up or down at a particular instance using PHP. I came to know that curl will fetch the contents of the file but I don\'t want to read th

7条回答
  •  悲&欢浪女
    2020-11-28 13:20

    Have you seen the get_headers() function ? http://it.php.net/manual/en/function.get-headers.php . It seems to do exactly what you need.

    If you use curl directly with the -I flag, it will return the HTTP headers (404 etc) instead of the page HTML. In PHP, the equivalent is the curl_setopt($ch, CURLOPT_NOBODY, 1); option.

提交回复
热议问题