PHP can detect websites in batches. php can detect websites in batches.

Source: Internet
Author: User

PHP can detect websites in batches. php can detect websites in batches.

This example describes how PHP can check whether a website can be opened normally in batches. We will share this with you for your reference. The details are as follows:

The curl_setopt function is an important function in php. It can imitate some user behaviors, such as user logon and registration.

<? Php // sets the maximum execution time to 120 seconds. ini_set ('max _ execution_time ', 120); function httpcode ($ url) {$ ch = curl_init (); $ timeout = 3; curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ ch, latency, 1); curl_setopt ($ ch, CURLOPT_HEADER, 1); curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_exec ($ ch); return $ httpcode = curl_getinfo ($ ch, CURLINFO_HTTP_CODE); curl_c Lose ($ ch) ;}$ check_web = array ('HTTP: // future,); for ($ I = 0; $ I <count ($ check_web ); $ I ++) {echo $ check_web [$ I]. '-> '. httpcode ($ check_web [$ I]). '<br>' ;}?>

Usage:

If it is displayed as 200, it is normal. If it is displayed with other values, it means it is abnormal. 3 after $ timeout is the set timeout seconds.

As follows:

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.