PHP Check whether the site is not down the way the example explained

Source: Internet
Author: User
This article mainly introduces the PHP check site is the method of downtime, combined with specific examples of PHP based on a curl session of the site to check the status of the relevant operation skills, the need for friends can refer to the following

Specific as follows:

<?phpfunction Networkcheck ($url) {$agent = "mozilla/5.0 (Windows NT 6.1; WOW64;  rv:42.0) gecko/20100101 firefox/42.0 ";  curl_init-Initializes a Curl session $ch =curl_init ();  Curl_setopt-set session parameters for a Curl curl_setopt ($ch, Curlopt_url, $url);  curl_setopt ($ch, curlopt_useragent, $agent);  curl_setopt ($ch, Curlopt_returntransfer, 1);  curl_setopt ($ch, Curlopt_verbose,false);  curl_setopt ($ch, Curlopt_timeout, 5);  curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE);  curl_setopt ($ch, curlopt_sslversion,3);  curl_setopt ($ch, Curlopt_ssl_verifyhost, FALSE);  Curl_exec-performs a curl session $page =curl_exec ($ch);  Curl_getinfo-gets the information for a Curl connection resource handle $httpcode = Curl_getinfo ($ch, Curlinfo_http_code);  The function of the Curl_close () function is to close a curl session, and the only argument is the handle returned by the Curl_init () function.  Curl_close ($ch);  if ($httpcode >=200 && $httpcode <300) return true; else return false;} The function parameter is the URL path of the site to be inspected if (Networkcheck ("https://www.baidu.com")) echo "Website OK"; else echo "Website down";? 

Run Result: Website OK

Related recommendations:

PHP Check If the site is down for instance code

Use Python to check the availability of your site in batches

An example of how PHP checks the site for downtime

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.