php定时计划任务的实现方法
最近由于项目需要定时对远程数据库上做一些处理,这里就需要做一个计划任务样子的东西了。
经过努力,终于使用php实现了这个定时计划任务,下面分享一下此次的实现过程。本次使用php实现计划任务主要使用了
ignore_user_abort() set_time_limit(0) sleep() 这三个函数。
具体的代码如下:
<p><?php</p>ignore_user_abort();//该函数的作用是当用户关掉浏览器后,PHP脚本也可以继续执行.<br />set_time_limit(3000);// 通过set_time_limit(0)可以让程序无限制的执行下去<br />$interval=5;// 每隔5s运行<br />//方法1--死循环<br />do{<br />echo '测试'.time().'<br/>'; <br />sleep($interval);// 等待5s <br />}while(true);<br />//方法2---sleep 定时执行<br />require_once './curlClass.php';//引入文件<br />$curl=new httpCurl('www.phpernote.com');//实例化<br />$stime=$curl->getmicrotime();<br />for($i=0;$i<=10;$i++){<br />echo '测试'.time().'<br/>'; <br />sleep($interval);// 等待5s<br />}<br />ob_flush();<br />flush();<br />$etime=$curl->getmicrotime();<br />echo '<hr>';<br /><p>echo round(($etime-stime),4);//程序执行时间</p>
在具体的实现过程中个人感觉PHP定时执行任务的效率并不高,建议关于定时执行任务的工作还是交给shell来做吧,相对来说,这个方法实现的太过勉强,而shell是专业级别的了。

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon

Announcement of 2025 PHP Situation Survey
