Created
January 3, 2016 12:13
-
-
Save iLiutaotao/d94d2561c2c6c192873e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function DeleteHtml($str) //清除字符串的空格 | |
{ | |
$str = trim($str); | |
$str = preg_replace("/\t/","",$str); | |
$str = preg_replace("/\r\n/","",$str); | |
$str = preg_replace("/\r/","",$str); | |
$str = preg_replace("/\n/","",$str); | |
$str = preg_replace("/ /","",$str); | |
$str = preg_replace("/ /","",$str); | |
return trim($str); | |
} | |
function send_post($url, $post_data) { //POST请求封装函数 | |
$postdata = http_build_query($post_data); | |
$options = array( | |
'http' => array( | |
'method' => 'POST', | |
'header' => 'Content-type:application/x-www-form-urlencoded', | |
'content' => $postdata, | |
'timeout' => 15 * 60 | |
) | |
); | |
$context = stream_context_create($options); | |
$result = file_get_contents($url, false, $context); | |
return $result; | |
} | |
$url = DeleteHtml($_GET['url']); //获取URL中需要监控的地址 | |
if($url == ""){ | |
echo "Error:Unknow URL"; | |
exit(); | |
} | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, $url); | |
curl_setopt($curl, CURLOPT_HEADER, 1); | |
curl_setopt($curl,CURLOPT_NOBODY,true); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |
$data = curl_exec($curl); | |
$code = curl_getinfo($curl,CURLINFO_HTTP_CODE); //获取HTTP状态码 | |
$post_data = array( | |
'amapi_pass' => '密钥', | |
'amh_cmd' => 'base64转码后的命令' | |
); | |
if($code == 502){ | |
send_post('http://AMH后台IP:端口/index.php?c=amapi&a=call', $post_data); //发现错误执行重启操作 | |
echo "Error:502"; | |
curl_close($curl); | |
exit(); | |
}else{ | |
curl_close($curl); | |
echo "当前URL:".$url; | |
echo "<br>当前状态:".$code; | |
echo "<br>执行完成"; | |
exit(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment