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

How to implement scheduled execution of php scripts under window

WBOY
Release: 2016-07-30 13:30:16
Original
1347 people have browsed it

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

<code> "D:<span>\phpStudy</span><span>\php</span>52<span>\php</span>.exe"  -f  "D:<span>\phpStudy</span><span>\WWW</span><span>\cron</span>.php"  -q "add_msg" "del_msg"</code>
Copy after login

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

php code

<code><span><span><?php</span><span>unset</span>(<span>$argv</span>[<span>0</span>]); 
<span>$m</span> = <span>isset</span>(<span>$argv</span>)?<span>$argv</span>:<span>''</span>;
<span>if</span>(<span>$m</span>){
    <span>foreach</span>(<span>$m</span><span>as</span><span>$v</span>){
       <span>$str</span>.= <span>$v</span>();
      }
   <span>exit</span>(<span>$str</span>);
}
<span>exit</span>(<span>'执行失败'</span>);

 <span><span>function</span><span>add_msg</span><span>()</span>{</span><span>return</span><span>'add_msg 执行成功'</span>.PHP_EOL;
}

<span><span>function</span><span>del_msg</span><span>()</span>{</span><span>return</span><span>'del_msg 执行成功'</span>;
}
<span>?></span></span></code>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template