开发原理:运行php的file_get_contents加http头进行访问,每次请求之后随机等待9-120s,这个参数可以自己调整!
运行效果:
需要注意inputT这个参数
php代码如下:
<?php
$urls = array(
'http://www.baidu.com/s?&inputT=',
'http://www.baidu.com/s?wd=*********&inputT=',
'http://www.baidu.com/s?bs=&inputT=',
'http://www.baidu.com/s?bs=&inputT=',
'http://www.baidu.com/s?&inputT='
);
$urlnum=count($urls);
$index = 0;
while(true){
$i++;
$sleepTime = mt_rand(9,120);//随机等待时间
$url = $urls[$index].mt_rand(380,3000);
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: zh-cn,zh;q=0.5\r\n" .
"Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7\r\n" .
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" .
"Accept-Encoding: gzip, deflate\r\n" .
"User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; Alexa Toolbar; mxie; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; SE 2.X MetaSr 1.0) \r\n" .
"Host: baidu.com\r\n" .
"Connection: Keep-Alive"
)
);
$context = stream_context_create($opts);
$html = file_get_contents($url, false, $context);
//echo $i."|$rand=>$index|$url\n";
if(++$index>=$urlnum) $index=0;
sleep($rand);
//sleep(5);
}
环境:linux+apache+php
需要在linux服务器上shell
命令:/usr/local/php5/bin/php /root/autorefresh.php
如果你需要在后端一直运行
命令:nohup /usr/local/php5/bin/php /root/autorefresh.php 2>&1 > /dev/null &
强大的linux呀,精典!!!