码迷,mamicode.com
首页 > Web开发 > 详细

php——离线执行任务

时间:2017-05-06 11:43:04      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:百度   cti   任务   数组   关闭   time   execution   open   fopen   

<?php
//设置忽略是否关闭终端窗口
ignore_user_abort(true);
ini_set(‘max_execution_time‘, ‘0‘);
//采集页面函数,看不懂执行百度curl php
/**
* $url:采集页面的路径
$name:离线获取数据存放的文件夹
*/
function getfiles($url,$name){
$name = $name.".txt";
$ch = curl_init("$url");
$fp = fopen("$name", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
sleep(5);
echo ‘<script>window.close();</script>‘;

}

getfiles($url,‘class‘);

//配置需要采集的页面路径数组
$urls = array(
‘http://www.cnblogs.com/jc535201285/p/6393761.html‘,
‘http://www.cnblogs.com/jianqingwang/p/6148644.html‘,
‘http://www.61916.com/news_view_2423.html‘,
‘http://blog.sina.com.cn/s/blog_8e326c350102w1ah.html‘,
‘http://www.w3school.com.cn/php/func_misc_ignore_user_abort.asp‘,
‘http://xinwen.eastday.com/a/170219205305597.html‘,
‘http://society.huanqiu.com/article/2017-02/10162630.html?from=bdwz‘,
‘http://www.cankaoxiaoxi.com/roll10/bd/20170220/1699670.shtml‘,
‘http://news.china.com/socialgd/10000169/20170220/30266284.html‘,
‘http://news.k618.cn/society/201702/t20170220_10368740.html‘,
‘http://fj.qq.com/a/20170218/029521.htm‘
);

//遍历数组
foreach($urls as $key=>$val){
getfiles($val,$key);
}


?>

php——离线执行任务

标签:百度   cti   任务   数组   关闭   time   execution   open   fopen   

原文地址:http://www.cnblogs.com/gaoxuqing/p/6815980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!