Home  >  Article  >  Backend Development  >  How to implement scheduled execution of php scripts under window

How to implement scheduled execution of php scripts under window

WBOY
WBOYOriginal
2016-07-30 13:30:161211browse

How to implement scheduled execution of php scripts under window
The purpose of the experiment is to execute a scheduled update script on the window
Experimental principle: Use the scheduled task of window to execute the bat script, and the bat script calls php.exe to execute the php script

bat script code

 "D:\phpStudy\php52\php.exe"  -f  "D:\phpStudy\WWW\cron.php"  -q "add_msg" "del_msg"

The parameter behind -f is the php script path
-q is the parameter passed to the php script

php code

unset($argv[0]); 
$m = isset($argv)?$argv:'';
if($m){
    foreach($mas$v){
       $str.= $v();
      }
   exit($str);
}
exit('执行失败');

 functionadd_msg(){return'add_msg 执行成功'.PHP_EOL;
}

functiondel_msg(){return'del_msg 执行成功';
}
?>

Test bat: Method 1: Enter the path of bat on the cmd command line and press Enter to execute
Method 2: Click the bat script directly to output text
Everything is ok, the rest is simple,
Open the scheduled task window of window
Create a basic task, enter a name and description, and click Next
Enter the called bat script, enter the time, click Next and click Finish

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.

The above introduces how to implement scheduled execution of PHP scripts under window, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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