Server Scheduled Tasks, scheduled access page (Windows/linux) _ Server Other

Source: Internet
Author: User
Tags curl php script set time sleep time limit

A simple word, chosen by the cloud-dwelling community, solves the problem.

Explorer "Http://www.jb51.net?opt=make"

Save the above code as Dositemap.bat. Then add to the scheduled task

Windows Planning Tasks

1, write a PHP program, named test.php, the content is as follows:

?  
  $fp = fopen ("Test.txt", "A +");  
  Fwrite ($fp, Date ("Y-m-d h:i:s"). "Success!" he said. \ n ");  
  Fclose ($FP);  

The program boldly writes, what include\require even if use, all have no problem

2, the new bat file, named Test.bat, the contents are as follows:

D:\php\php.exe-q D:\website\test.php

Write your own bat file, regularly open the page, and close IE browser

Explorer.exe open=http://www.jb51.net
ping-n 127.1>nul
taskkill/f/im "Iexplore.exe"

3. Set up Windows Planning task:
Start –> Control Panel –> Task Schedule –> Add Task Schedule
Browse folder Select the bat file above
Set time and password (log on to Windows)
You can save it.
4, over! You can right-click the scheduled task point "run" to try

Second, the Linux script implementation

First, use PHP to execute scripts in crontab
Just like calling a normal shell script in crontab (specifically crontab usage), use a PHP program to invoke the PHP script.
The following myscript.php are performed every hour:

**# crontab-e** 

/usr/local/bin/php is the path to the PHP program.

Ii. using URLs to execute scripts in crontab
If your PHP script can be triggered by a URL, you can use Lynx or curl or wget to configure your crontab.
The following example uses a Lynx text browser to access URLs to execute PHP scripts every hour. The Lynx text browser opens the URL by default using the dialog method. However, like the following, we use the-dump option in the Lynx command line to convert the URL output to standard output.

 
 

The following example uses the Curl access URL to execute a PHP script every 5 minutes. Curl defaults to display output in standard output. With the "curl-o" option, you can also dump the output of the script to a temporary file.

 
 

The following example uses the wget access URL to execute a PHP script every 10 minutes. The-q option indicates quiet mode. "-O Temp.txt" indicates that the output is sent to a temporary file.

 
 

Third, PHP implementation of scheduled Tasks
using PHP to refresh your browser requires several issues
1.PHP script Execution time limit, the default is 30m solution: Set_time_limit () or modify php.ini set Max_execution_time time (not recommended)
2. If the client browser is closed, the program may be forced to terminate, the solution: Ignore_user_abort even if the shutdown page is still normal execution
3. If a program has been implemented that is likely to consume a large amount of resources, the solution uses sleep using the program to hibernate for a while and then executes
PHP timed Execution Code:

<?php  
  Ignore_user_abort ()//Turn off the browser, the PHP script can also continue to execute.  
  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 '//Introducing file  

   $curl = new Httpcurl ()//instantiating  
   $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 '  
 

It's not very efficient when you test it.
Summarize:
It is recommended that the work on the scheduled tasks be given to the shell to do it, compared to the king.

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.