php采集回调

来源:互联网 发布:深圳淘宝客服工资多少 编辑:程序博客网 时间:2024/06/06 16:32
<?phpinclude('CURL.php');$db=new PDO('mysql:dbname=haicheji;host=localhost','root','123456');$db->exec("set names utf8");$curl=new CUrl();$curl->task='demo4_addTask';$curl->go();//取还没有添加的任务function demo4_addTask(){global $baseUrl,$db,$curl;static $lastId=0;$limit=100;$list=$db->query("select id,url from html where id>$lastId and tag is null order by id limit $limit")->fetchAll();if(count($list)>0){foreach($list as $v){$url=array($v['url']);$callback=array('demo4_cb1',array($v['id']));$curl->add($url,$callback);}$lastId=$v['id'];}else $lastId=$lastId+1;}//处理回调函数function demo4_cb1($r,$id){global $db,$curl;if($r['info']['http_code']==200){$html=$r['content'];$rs=$db->prepare("update html set html=?,tag=1 where id=?");$rs->execute(array($html,$id));}$curl->status();}

0 0
原创粉丝点击