解决方案 »
- 不知道为啥,一点儿都显示不了
- select语句
- 请教基于Zend Framework开发的开源项目
- $this->assign的用法 请高人指点
- 请问大家,在PHP中,怎么获取一段时间内的日期列表啊???
- 如何将mysql4 中的datetime时间列转换成unix时间列?
- 取总数时,用select count(*) 和 select count(id),id为主键,在效率上有区别吗?
- Php4.39 ftp函数在4.06版本中不可用?请教解决办法???***
- 为什么下面的这段上传文件的程序在本机能用,上传到服务器后就不能用?!急呀!!!!!
- PHP中可以调用c函数吗?
- 求教一个PHP采集代码的写法
- CURL无法请求本地
curl_setopt($ch,CURLOPT_URL,"http://bbs.csdn.net/topics/390781797");
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$html = curl_exec($ch);
curl_close($ch);
list($header, $body) = explode("\r\n\r\n", $html, 2);
var_dump(http_parse_headers($header));
http_parse_headers() 需要另外下载,参考:
http://stackoverflow.com/questions/6368574/how-to-get-the-functionality-of-http-parse-headers-without-pecl
$ch = curl_init();
$list1=array('www.baidu.com','www.taobao.com','www.alipay.com','localhost/kk/','www.yy.net');
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 1);
for($i=0;$i<count($list1);$i++)
{
curl_setopt($ch,CURLOPT_URL,$list1[$i]);
curl_exec($ch);
echo $list1[$i];
$httplist=curl_getinfo($ch,CURLINFO_HTTP_CODE);
var_dump($httplist);
}
curl_close($ch);
这个怎么样,我想批量检测,可是好像很慢,几秒后才有反馈
$result = @get_headers('http://www.qqhaowan.com');
if ($result) {
print_r($result);
if (strpos($result[0], '200')) {
echo '网站能访问!';
} else {
echo '网站不能访问!';
}
} else {
echo '目标URL无法打开!';
}
好像一上for循环就不行了。。
测试过,可以循环检测。<?php$sites = array('http://www.baidu.com','http://www.21cn.com','http://www.sina.com.cn','http://www.csdn.net');foreach($sites as $site){
echo $site.':'.checksite($site).'<br>';
}function checksite($url){
$result = @get_headers($url); if($result){
if(strstr($result[0], '200')!=''){
return true;
}
}
return false;
}?>
echo $site.':'.checksite($site).'<br>';
}function checksite($url){
$result = @get_headers($url); if($result){
if(strstr($result[0], '200')!=''){
return true;
}
}
return false;
}?>
的确,可以了。难道是因为上面那个时间太短,没有得到回应?