Tips for Windows to perform PHP regularly

Source: Internet
Author: User
Tags current time sql mysql rar require system log mysql database backup

Windows timed to execute PHP believe that many readers (PHP enthusiasts) in the work, learning process often complained: in Win how to let PHP timed automatically?? How to allow MySQL to achieve automatic backup without worry?? If you rely entirely on hand to do of course can also be achieved, but the operation seems too cumbersome a little! Take it easy. Using the system's Task Scheduler (which Windows 98 calls a scheduled task) can easily solve the problem. This function is often overlooked by many users or never thought of:).

The so-called task plan is that the computer automatically calls the user to set up the application in advance, so as to simplify the user's operation. With the Windows 2000 Task Scheduler (which is no longer detailed here with the Cron program under *nix), we can schedule any script, program, or document to run at the most appropriate time to meet our needs. Let's take Windows 2000 for example.

Specifically, if we need to run the Task Scheduler automatically, we should perform the following steps:

1. Click the Start button and then select programs → attachments → system tools → task Scheduler (or "settings" → "Control Panel" → "Scheduled Tasks") to start the Task Scheduler management program for Windows 2000.

2. In the Task Plan window, double-click the Add Task Schedule icon, start the Task Scheduler Wizard for the system, and then click Next, select the application that you want to run automatically in the list of programs that you give, and then click the Next button.
Set the appropriate task schedule name and select the frequency of time to automate this task, such as Daily, weekly, monthly, one-time, every time you start your computer, and so on, and then click the Next button.
At this point, the system will require the user to the program to run the specific time to set, such as the number, the clock, which time to run, and so on, we just need to set according to their own needs.

4. The system will then require the user to set the appropriate username and password so that the system can be run automatically in the future.

5. Finally, we simply click the Finish button to add the task to the Windows 2000 Task Scheduler, and thereafter it automatically "remembers" the task, which automatically invokes the user-specified application once the system time and related conditions match the user-set schedule ( Each time you start Windows 2000, the Task Scheduler starts automatically and runs in the background to ensure that the user's schedule is executed on time.

Now let's test whether the task we just built was successful, right-click the "PHP" program icon (as shown in Figure 6), and select "Run" in the pop-up menu. In general, the program icon as long as the activation of the operation can start normally. If the run failed to see if the user and password are set correctly, and to determine whether the "Task Scheduler" service has been started, I was in order to save the system resources to turn it off, causing the operation failed, I found a long day. In addition, you can also see from the system log what causes the run to fail.

Okay, so much for the application of the mission plan, now that we cut to the chase, here are two examples:

First, let PHP run it regularly!
1, edit the following code, and save as test.php:
<?php
$fp = @fopen ("Test.txt", "A +");
Fwrite ($fp, Date ("Y-m-d h:i:s"). "Let PHP run at regular intervals!" \ n ");
Fclose ($FP);
?>
Open Text input: D:\php4\php.exe-q D:\php4\test.php
Save As. bat format.
D:\php4\php.exe is the PHP installation path, D:\php4\test.php is the path to the program to run regularly.

2, add a task plan, select the. bat file

3, the time is set to run every 1 minutes, and then run this task.

4, now we look at the content of the D:\php4\test.txt file is successful. If the content is as follows, congratulations on your success.

2003-03-03 11:08:01 let PHP run regularly!
2003-03-03 11:09:02 let PHP run regularly!
2003-03-03 11:10:01 let PHP run regularly!
2003-03-03 11:11:02 let PHP run regularly!

Second, let MySQL realize automatic backup become possible!
1, edit the following code, and save as backup.php, if you want to compress can copy a rar.exe:
<?php
if ($ARGC!= 2 In_array ($argv [1], Array ('--help ', '-? ')) {
?>
Backup Ver 0.01, for Win95/win98/winnt/win2000/winxp on I32
Copyright (C) Ptker All rights reserved. Http://www.dareng.com
This are free Software,and your are welcome to modify and redistribute it
Under the GPL license

PHP Shell script for the backup MySQL database.

Usage: <?php echo $argv [0];?> <option>

<option> can is database name you would like to backup.
With the--help, or-? Options, you can get this help and exit.
<?php
} else {
$dbname = $argv [1];
$dump _tool = "C:\\mysql\\bin\\mysqldump";
$rar _tool = "D:\\php4\\rar";
@exec ("$dump _tool--opt-u User-ppassword $dbname >./$dbname. sql");
@exec ("$rar _tool a-ag_yyyy_mm_dd_hh_mm $dbname. rar $dbname. sql");
@unlink ("$dbname. sql");
echo "Backup complete!";
}
?>

2, add a task plan, in (as shown in Figure 2) This step to enter the command:
D:\php4\php.exe-q D:\php4\backup.php DatabaseName
3, the time is set to run once a day, and then run this task.
4, the final will be in the d:\php4\ directory to generate a database name and the current time composed of a RAR file.
5, Congratulations! It's done!
Of course there are many ways to backup, readers can do according to their favorite to do!



The above is the original. Combined with my real cheap, the supplementary note is as follows:

1. If an error occurs:
An error occurred while trying to set up task account information
The specified error is:
0x80070005: Access Denied
You do not have permission to run the requested operation

On the top ' 4. The system will then require the user to set the appropriate username and password (as shown in Figure 5) so that the system can be run automatically in the future. It is best to use the "system" user and the password may be blank.

This system has a very high privilege, higher than your administrator, so you should not do anything when you run the command, this is not an unconditional implementation of any hint, this permission under you kill the core process is OK.



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.