| Have you ever thought about regularly executing php code in windows? The idea is cool and it is not difficult to implement it. if you have any need, you can refer to the introduction in this article.
You can use windows scheduled tasks to regularly call the PHP script in three steps. For details about how to regularly execute php in Linux, refer to: Introduction to the regular php execution method. For more information about the principles of scheduled tasks, see: Understanding the implementation principles of php scheduled tasks. With the above knowledge, we will start learning today.
Solution steps: 1. create a php script
Ghost is different from our web root directory, while php's file directory function can only operate within the web root directory range, so we need to use the absolute path, otherwise, the code will be correctly executed, but the file will not be created.
2. create a. bat file:
"D:\Program Files (x86)\Web\PHP\php.exe" -f "D:\Program Files (x86)\Web\www\root\go.php"
Save and name it run. bat. Note: If your PHP directory or web root directory contains spaces, you need to use quotation marks to reference the entire path; otherwise, an error will occur. The webmaster's directory contains spaces, so quotation marks are used. When creating your own bat file, please decide whether to use quotation marks and the Directory of the file according to your own situation.
3. add a windows scheduled task to open the scheduled task from the control panel (this is mainly for win7 users), click "create basic task", and enter the name and description, click "next", select the task execution frequency, understand it well, click "next", set the task execution time, click "next", and select "Start Program ", click "next" and click "browse" to select the "run. bat file, click "next", and click "finish".
4. the system runs automatically on a regular basis based on the time you set. you can also manually execute the task if you cannot wait. Find the task you just created in the task name in the middle column of the scheduled task, double-click the task, and click the run button on the right. a cmd dialog box is displayed and closed, this indicates that your script has been correctly executed. check whether the file is created in the directory where the file is created.
Try it on your computer. |