Home >Backend Development >PHP Tutorial >php detects whether the website is opened normally
PHP method to implement batch detection of whether the website can be opened normally
The curl_setopt function is an important function in PHP, it can imitate the user's Some behaviors, such as imitating user login, registration and other user-operable behaviors.
Instance:
<?php //设置最大执行时间是 120秒 ini_set('max_execution_time',120); function httpcode($url){ $ch = curl_init(); $timeout = 3; curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch,CURLOPT_RETURNTRANSFER,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_close($ch); } $check_web = array( '//www.jb51.net/', 'http://sc.jb51.net/', 'http://tools.jb51.net/', 'http://baike.jb51.net/', 'http://demo.jb51.net/', 'http://demo2.jb51.net/', ); for($i=0;$i<count($check_web);$i++){ echo $check_web[$i].' -> '.httpcode($check_web[$i]).'<br>'; } ?>
Usage:
If displayed If it is 200, it is normal. If other values are displayed, it means it is abnormal; the 3 after $timeout is to set the timeout seconds.
The rendering is as follows:
## Recommended tutorial:
The above is the detailed content of php detects whether the website is opened normally. For more information, please follow other related articles on the PHP Chinese website!