《PHP實(shí)例:如何離線執(zhí)行php任務(wù)》要點(diǎn):
本文介紹了PHP實(shí)例:如何離線執(zhí)行php任務(wù),希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
直接上代碼,主要函數(shù)PHP應(yīng)用
ignore_user_abort(true);PHP應(yīng)用
這個(gè)函數(shù)忽略了終端被關(guān)閉(打開(kāi)的網(wǎng)頁(yè)被關(guān)閉),后面PHP應(yīng)用
getfiles()這函數(shù)是執(zhí)行采集任務(wù)的自定義函數(shù),后面又配置了下路徑PHP應(yīng)用
打開(kāi)寫(xiě)好的頁(yè)面,關(guān)閉,后面發(fā)現(xiàn)任務(wù)都能執(zhí)行完成,有興趣的可以試試.PHP應(yīng)用
<?php //設(shè)置忽略是否關(guān)閉終端窗口 ignore_user_abort(true); ini_set('max_execution_time', '0'); //采集頁(yè)面函數(shù),看不懂執(zhí)行百度curl php 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>'; } //配置需要采集的頁(yè)面路徑數(shù)組 $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' ); //遍歷數(shù)組 foreach($urls as $key=>$val){ getfiles($val,$key); } ?>
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持維易PHP!PHP應(yīng)用
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/1709.html