Writing and Automating PHP Crons in Windows and Linux : Page 4
Find out how to automate PHP scripts so they run unattended at scheduled times on both Windows and Linux.
by Octavia Andreea Anghel
Nov 14, 2008
Page 4 of 4
Running PHP Crons in Windows XP
Here's the equivalent Windows XP process to schedule a cron:
Launch Scheduled Tasks from Start ( All Programs ( Accessories ( System Tools ( Scheduled Tasks.
Right-click on "Add Scheduled Task," and select the Open option from the context menu (see Figure 10, left). Click the Next button (see Figure 10, right).
Figure 10. Initializing a Task in Windows XP: Fewer options makes it simpler to create tasks in Windows XP.
In the window that appears, click the Browse button and navigate to the cron.bat file. Press the Open button to select when to run the script (see Figure 11). After selecting the script frequency, press Next to continue.
Figure 11. Windows XP Task Settings: Enter a name for the task, and select when the task should run.
The next window lets you select the time, date, and frequency for the task (see Figure 12). Press the Next button to continue.
Figure 12. Windows XP Task Settings: Enter a name for the task, and select when the task should run.
Finally, specify the name and the password of the user account under which the task should execute, and then press Next (see Figure 13).
Figure 13. Enter Account: Enter the account name and password under which the task should run.
Figure 14. Task Scheduled: You'll see this screen when you've successfully scheduled the task.
You'll see a review of your cron configuration (use the Back button to adjust the selected parameters). If everything is OK, press Finish (see Figure 14).
Figure 15. Completed Task: The completed task appears in the Scheduled Tasks list. To run the task, right-click on it, and select Run.
Author's Note: If you want to have access to more detailed configurations, select the "Open advanced properties " checkbox from Figure 15 before pressing the Finish button.
When you click Finish, XP creates the cron, and you should see it in the Scheduled Tasks list as shown in Figure 15. To test it, right-click it and select Run from the context menu. From this menu you also may delete/rename a cron and access its properties.
Running PHP scripts as cron tasks is a simple and elegant solution when you need to control the infrastructure and environment of your web sites. Crons can save you from the repetitive, time-consuming, and boring task of monitoring and executing activities. Executing them at low-traffic periods times will generate great results.
Octavia Andreea Anghel is a senior PHP developer currently working as a primary trainer for programming teams that participate at national and international software-development contests. She consults on developing educational projects at a national level. She is a coauthor of the book "XML Technologies—XML in Java" (Albastra, ISBN 978-973-650-210-1), for which she wrote the XML portions. In addition to PHP and XML, she's interested in software architecture, web services, UML, and high-performance unit tests.