php c-url v-eto
2016-05-06 15:35
211 查看
** * Created by PhpStorm. * User: hxg * Date: 2016/5/4 * Time: 10:47 */ class TestAction extends CommonAction { public function toupiao(){ set_time_limit(10); //$agent=$_SERVER['HTTP_USER_AGENT']; $agent='Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3'; $url='http://tp.zztc.com/index.php?g=Wap&m=Vote&a=vote'; $url=htmlspecialchars_decode($url); $data = array ( 'token' => 'vjcbgt1414375209', 'id' => '28', 'wecha_id' => '', 'tid' => '18' ); $options= array( CURLOPT_URL => $url, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $agent, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT=>5, CURLOPT_POST=>1, CURLOPT_POSTFIELDS=>$data ); $count=200; $start=0; $okCount=0; $yiCount=0; $errCount=0; $info='====================*****Start****=====================<br/>'; while (true) { $res = $this->getUrlContent($url, $agent, $timeOut = 1, $options); $res=json_decode($res,true); $start++; if($res['status']==2) { $okCount++; }elseif($res['status']==4){ $yiCount++; }else{ $errCount++; } $info.=date("Y-m-d H:i:s",time()).': '.$res['info'].'<br/>'; if($start==$count)break; $ran=rand(3,10); sleep($ran); } $info.='====================*****End****=====================<br/>'; echo '成功:'.$okCount.'<br/>'; echo '重复:'.$yiCount.'<br/>'; echo '失败:'.$errCount.'<br/>'; echo '*总投*:'.$start.'<br/>'; echo '<br/><br/>'.$info; //$url2='http://tp.zztc.com/index.php?g=Wap&m=Vote&a=show&token=vjcbgt1414375209&id=28&wecha_id=&tid=18&from=timeline&isappinstalled=0'; //$surveyCount=$this->getSurveyCount($url2,$agent,$timeOut=5); } public function ajaxtoupiao(){ set_time_limit(10); //$agent=$_SERVER['HTTP_USER_AGENT']; $agent='Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3'; $url='http://tp.zztc.com/index.php?g=Wap&m=Vote&a=vote'; $url=htmlspecialchars_decode($url); $data = array ( 'token' => '', 'id' => '', 'wecha_id' => '', 'tid' => '' ); $options= array( CURLOPT_URL => $url, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $agent, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT=>5, CURLOPT_POST=>1, CURLOPT_POSTFIELDS=>$data ); $res = $this->getUrlContent($url, $agent, $timeOut = 1, $options); $res=json_decode($res,true); $res['info']=date('Y-m-d H:i:s',time()).'---'.$res['info']; $this->ajaxReturn($res,'jsonp'); } /** * 模拟获取网页内容 * @param $url 目标网址 * @param $agent 客户端信息 */ private function getUrlContent($url,$agent,$timeOut=5,$op){ $ch= curl_init(); $options= array( CURLOPT_URL => $url, CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $agent, CURLOPT_FOLLOWLOCATION => true, CURLOPT_TIMEOUT=>$timeOut//cs ); $options=empty($op)?$options:$op; curl_setopt_array($ch, $options); $output= curl_exec($ch); curl_close($ch); return $output; } private function getSurveyCount($url,$agent,$timeOut=5){ //$html=$this->getUrlContent($url,$agent,20); $html='<div class="xuanshou"> <dl><dt>阿进</dt><dd>选手姓名</dd></dl> <dl><dt>28</dt><dd>该选手编号</dd></dl> <dl><dt>658</dt><dd>当前票-数</dd></dl> <dl><dt>4</dt><dd>当前排名</dd></dl> </div>'; //preg_match_all("/<img([^>]*)\s*src=('|\")([^'\"]+)('|\")/i",$html,$match);//带引号 preg_match_all("/<div.*class=\"xuanshou\">\s*(<dl><dt>.*<\/dt><dd>.*<\/dd><\/dl>)*\s*<\/div>/",$html,$match);//带引号 //preg_match_all("/<dt>[0-9]*<\/dt>/",$html,$match);//带引号 return $match[3]; }
<html> <head> <script src="http://res.jiemian.com/static/pick/pc/plugins/jquery/jquery-1.10.2.min_efbb506.js" type="text/javascript"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>投票</title> </head> <body> <div> <a href='javascript:void(0)' onclick='sss();' >Click Me!</a><br/> 成功:<span id='okCount'></span><br/> 重复:<span id='yiCount'></span><br/> 失败:<span id='errCount'></span><br/> 请求次数:<span id='stsrt'></span><br/> 总共:<span id='count'></span><br/> </div> <div id='jid'> </div> </body> </html> <script> var count=300; var start=0 var okCount=0; var yiCount=0; var errCount=1; function sss(){ var time=selectfrom(20,50); time=time*1000; timeID = setInterval(function(){ajaxPost()},time); } function selectfrom (lowValue,highValue){ var choice=highValue-lowValue+1; return Math.floor(Math.random()*choice+lowValue); } function ajaxPost(){ if(start>=count){ clearTimeout(timeID); return false; } $.ajax({ url:'http://a.jiemian.com/index.php?m=test&a=ajaxtoupiao', dataType:'jsonp', type:'post', data:'', success:function(data){ var status=data.status; if(status==2){ okCount=okCount+1; }else if(status==4){ yiCount=yiCount+1; }else if(status==undefined ||status==''){ errCount=errCount+1; }else{ errCount=errCount+1; } $('#jid').append("<span>"+data.info+"</span><br/>") } }) start++; $("#stsrt").html(start); $("#count").html(count); $("#okCount").html(okCount); $("#yiCount").html(yiCount); $("#errCount").html(errCount); } </script>
相关文章推荐
- Laravel5框架的搭建
- 编辑器phpstrom的快捷键修改
- PHP 中的设计模式详解
- PHP使用数据库的并发问题(转)
- php在windows server 2012的iis8下面的安装
- Windows的程序性能分析和函数呼叫列表工具LTProf (Call Graph at Runtime)
- PHP自学no00014预定义常量
- PHP自学no00013常量定义取值判定是否已定义
- php获取域名方法
- PHP自学no00012数据类型检测
- php开源项目大全
- Eclipse/ZendStudio更换主题风格
- PHP使用出现 Fatal error: Class 'SQLite3' not found
- PHP自学no00011数据类型转换
- PHP自学no00010特殊数据类型之空值
- PHP自学no00009数据类型浮点型之圆周率输出
- Zendstudio 设置默认方法注释
- zend studio导入thinkphp的乱码问题
- PHP自学no00008数据类型整数型多进制输出
- Yii 将对象转化成数组