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 获取任意月的最后一天

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

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

In this chapter, we are going to learn the following topics related to routing ?

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

Validator can be created by adding the following two lines in the controller.
