最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
如何离线执行php任务
时间:2017-04-21 编辑:简简单单 来源:一聚教程网
直接上代码,主要函数
ignore_user_abort(true);
这个函数忽略了终端被关闭(打开的网页被关闭),后面
getfiles()这函数是执行采集任务的自定义函数,后面又配置了下路径
打开写好的页面,关闭,后面发现任务都能执行完成,有兴趣的可以试试。
代码如下 | 复制代码 |
//设置忽略是否关闭终端窗口 ignore_user_abort(true); ini_set('max_execution_time','0'); //采集页面函数,看不懂执行百度curl php functiongetfiles($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''; } //配置需要采集的页面路径数组 $urls=array( 'http://www.cnblogs.com/jianqingwang/p/6373168.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($urlsas$key=>$val){ getfiles($val,$key); } ?> |
-
下一个: php正则表达式基本知识与应用
相关文章
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24
- php数组查询元素位置方法介绍 10-24