<?php
include('CURL.php');
$db=new PDO('mysql:dbname=dbname;host=127.0.0.1','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 images where id>$lastId and tag is null order by id limit $limit")->fetchAll();
if(count($list)>0){
foreach($list as $v){
$src=$v['url'];
$ext=pathinfo($src,PATHINFO_EXTENSION);
$imgname = 'E:/pic/'.$v['id'].'.'.$ext;
$url=array($src,$imgname);
$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){
if($db->exec("update images set tag=1 where id=$id")){
}
}
$curl->status();
}
curl类,需要调用的,查看下一篇文章
curl多线程采集图片案例
最新推荐文章于 2021-03-09 23:26:42 发布