Implementation of PHP planning tasks

Source: Internet
Author: User
Tags curl execution functions php script sleep

Recently, because the project needs to do some processing on the remote database regularly, there is a need to do a planning task. After efforts to finally use PHP to achieve this planning task, the following share the implementation process.

This time using the PHP implementation planning task mainly uses the Ignore_user_abort () set_time_limit (0) sleep () these three functions.

The specific code is as follows:

<?php
Ignore_user_abort ()//The function is that the PHP script can continue to execute after the user has turned off the browser.
Set_time_limit (3000);//Through Set_time_limit (0) allows the program to execute indefinitely
$interval =5;//every 5s run
//Method 1--dead loop
do{
	echo ' Test '. Time (). ' <br/> '; 
	Sleep ($interval);//wait 5s    
}while (true)
; Method 2---Sleep timed execution
require_once './curlclass.php '//File
$curl =new httpcurl (' www. Alixixi.com ')//instantiate
$stime = $curl->getmicrotime ();
For ($i =0 $i <=10; $i + +) {
	echo ' Test '. Time (). ' <br/> '; 
	Sleep ($interval);//wait for 5s
}
Ob_flush ();
Flush ();
$etime = $curl->getmicrotime ();
Echo ' 

In the specific implementation of the process of personal feeling PHP time to perform the task of the efficiency is not high, suggest that the task of scheduled tasks or to the shell to do it, relatively speaking, this approach to achieve too reluctantly, and the shell is professional level.

Articles that you may be interested in

    • Win7 set up for scheduled tasks
    • PHP statistics online numbers, accurate statistics online number of ways
    • PHP Records search engine antecedents and search input keywords
    • PHP to determine the most secure upload file type, the most realistic solution
    • What is the PHP design pattern and how do you understand
    • Use PHP functions in Smarty Templates and how to use multiple functions for a variable in smarty templates
    • The operating mechanism and principle of PHP bottom
    • PHP gets the last day of any month


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.