php简单定时执行任务的实现方法
这篇文章主要介绍了php简单定时执行任务的实现方法,涉及curl及sleep等操作技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了php简单定时执行任务的实现方法。分享给大家供大家参考。具体实现方法如下:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
ignore_user_abort(); set_time_limit(0); $interval = 60*5; do{ $url = "http://www.sina.com.cn/"; $ch = curl_init();//创建一个新的curl会话 curl_setopt($ch,CURLOPT,$url);//设置需要抓取的cURL curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); //设置cURL参数,要求结果保存到字符串还是页面(1或真表示保存而不输出) curl_setopt($ch,CURLOPT_TIMEOUT,2);//最大延续2秒 $result = curl_exec($ch);//执行 curl_close($ch);//关闭 sleep($interval);//休息5分钟 }while(true); ?> |
希望本文所述对大家的php程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
