How to Implement regular script execution in PHP in windows

Source: Internet
Author: User
How to Implement regular script execution in PHP in windows
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.

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.