search
Homephp教程php手册php计划任务的实现

最近由于项目需要定时对远程数据库上做一些处理,这里就需要做一个计划任务样子的东西了。经过努力,终于使用php实现了这个计划任务,下面分享一下此次的实现过程。

本次使用php实现计划任务主要使用了 ignore_user_abort() set_time_limit(0) sleep() 这三个函数。

具体的代码如下:

<?php
ignore_user_abort();//该函数的作用是当用户关掉浏览器后,PHP脚本也可以继续执行.
set_time_limit(3000);// 通过set_time_limit(0)可以让程序无限制的执行下去
$interval=5;// 每隔5s运行
//方法1--死循环
do{
	echo '测试'.time().'<br/>'; 
	sleep($interval);// 等待5s    
}while(true);
//方法2---sleep 定时执行
require_once './curlClass.php';//引入文件
$curl=new httpCurl('www.Alixixi.com');//实例化
$stime=$curl->getmicrotime();
for($i=0;$i<=10;$i++){
	echo '测试'.time().'<br/>'; 
	sleep($interval);// 等待5s
}
ob_flush();
flush();
$etime=$curl->getmicrotime();
echo '<hr>';
echo round(($etime-stime),4);//程序执行时间

在具体的实现过程中个人感觉PHP定时执行任务的效率并不高,建议关于定时执行任务的工作还是交给shell来做吧,相对来说,这个方法实现的太过勉强,而shell是专业级别的了。

您可能感兴趣的文章

  • win7计划任务的设置
  • php统计在线人数,精确的统计在线人数的办法
  • PHP记录搜索引擎来路以及搜索输入的关键字
  • PHP判断上传文件类型最安全,最真实的解决办法
  • php设计模式是什么,该如何理解
  • smarty模板中使用php函数以及smarty模板中如何对一个变量使用多个函数
  • PHP底层的运行机制与原理
  • php 获取任意月的最后一天



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

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),

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool