1.实现网站检测代码
点击(此处)折叠或打开
-
/**
-
* Author: magic ysjheeqg#163.com
-
* Date: 15-1-2
-
* Time: 11:48
-
* 网站状态检测
-
*/
-
header("Content-type: text/html; charset=utf-8");
-
include('functions.php');
-
-
$email_config = array(
-
'smtp_host' => 'smtp.163.com',
-
'smtp_port' => '25',
-
'from_email' => 'ysjheeqg@163.com',
-
'from_name' => 'LaiKinsan',
-
'smtp_user' => 'yulongshuiji',
-
'smtp_pass' => '',
-
'reply_email' => 'ysjheeqg@163.com',
-
'reply_name' => 'LaiKinsan',
-
'email_arr' =>array(
-
'7878233@qq.com',
-
'8292389@qq.com',
-
),
-
'test_email' => '777777@qq.com',
-
);
-
-
check_status("");
-
-
-
//region 检测网站状态
-
function check_status($url)
-
{
-
global $email_config;
-
$ch = curl_init();
-
if (!$ch) {
-
die("没开curl模块功能");
-
}
-
curl_setopt($ch, CURLOPT_URL, $url);
-
curl_setopt($ch, CURLOPT_HEADER, 1); //获取http头信息
-
curl_setopt($ch, CURLOPT_NOBODY, 1); //不返回html的body信息
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //返回数据流,不直接输出
-
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //超时时长,单位秒
-
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
-
curl_exec($ch);
-
$info = curl_getinfo($ch);
-
curl_close($ch);
-
$string = $info['http_code'];
-
-
if ($string === 200) {
-
echo "ok";
-
} else {
-
foreach($email_config['email_arr'] as $k =>$v){
-
$res = send_mail($v, '', '网站问题通知邮件', '这是一封通知邮件,如果收到了说明网站访问有问题,问题网址'.$url, '', $email_config);
-
if ($res == 1) {
-
echo "测试邮件已经发往你的邮箱";
-
} else {
-
echo "测试邮件发送失败";
-
}
-
}
-
- }
- }