php detects whether the website is opened normally

王林
Release: 2023-04-07 13:38:01
Original
3921 people have browsed it

php detects whether the website is opened normally

<?php
//设置最大执行时间是 120秒
ini_set(&#39;max_execution_time&#39;,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(
&#39;//www.jb51.net/&#39;,
&#39;http://sc.jb51.net/&#39;,
&#39;http://tools.jb51.net/&#39;,
&#39;http://baike.jb51.net/&#39;,
&#39;http://demo.jb51.net/&#39;,
&#39;http://demo2.jb51.net/&#39;,
);
for($i=0;$i<count($check_web);$i++){
  echo $check_web[$i].&#39; -> &#39;.httpcode($check_web[$i]).&#39;<br>&#39;;
}
?>
Copy after login

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:

PHP video 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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template