Tips for Windows to execute PHP at timed time

Source: Internet
Author: User
Tags mysql automatic backup

Windows timed to execute PHP believe that a lot of readers (PHP enthusiasts) in the process of work, learning often complain: in win how to let PHP timed automatic letter?? How to make MySQL automatic backup without worries?? If you rely entirely on manual work can also be achieved, but the operation seems to be too cumbersome a bit! Don't worry, this problem can be easily solved by using the system's Task Scheduler, which Windows 98 calls a scheduled task. This feature is often overlooked by many users or never thought of:).

The so-called task plan is the computer automatically call the user pre-set application, so as to simplify the purpose of user operations. With the Task Scheduler for Windows 2000 (rather than the Cron program under *nix, which is no longer detailed here), we can schedule any script, program, or document to run at the most appropriate time to meet our needs. The following is an example of Windows 2000.

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

1. Click the Start button, then select programs → accessories → system tools → task scheduler (or settings → control Panel → Task Scheduler) to start the Task Scheduler Manager for Windows 2000. \ r \ \

2. In the Scheduled Tasks window, double-click the Add Scheduled task icon, launch the system's Task Scheduler Wizard, and then click the Next button, select the application that you want to run automatically in the list of programs that you have given, and then click Next.
Set the appropriate schedule name and select how often the task will be automatically performed (such as Daily, weekly, monthly, one-time, every start of the computer, every logon, and so on), and then click the Next button.
At this time the system will require users to run the program to set the specific time, such as the number of minutes, which several time period to run, we just need to set according to their own needs.

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

5. Finally, we simply click the "Finish" button to add the task to the Windows 2000 Task Scheduler, then it will automatically "remember" this task, once the system time and related conditions and the user set the plan to match, it will automatically invoke the user's designated application, it is very convenient ( Each time you start Windows 2000, the Task Scheduler starts automatically and runs in the background to ensure that the user's schedule executes on time.

Now let's test the success of the task you just built, right-click on the "PHP" program icon (6) and select "Run" in the popup menu. In general, the program icon can start normally as long as it is activated. If the run fails to see whether the user and password are set correctly, and whether the "Task Scheduler" service has been started, I was originally to save the system resources to turn it off and cause the operation failed, I found a big half day. You can also check the "system log" to see what is causing the operation to fail.

Okay, so much for the mission plan application, now let's cut to the chase, and here are two examples:

First, let PHP run 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 it regularly!" \ 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 of the program to run on a timed basis.

2. Add a task plan and select the. bat file

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

4. Now let's see if the content of the D:\php4\test.txt file is successful. If the content is as follows, congratulations on your success.

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

Second, let MySQL realize automatic backup becomes possible!
1, edit the following code, and save as backup.php, if you want to compress a rar.exe can be copied:
<?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 was free Software,and 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 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 (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. Finally, a RAR file consisting of the database name and the current time will be generated in the D:\php4\ directory.
5, congratulate you! It's done!
Of course there are many ways of backup, readers can do as they like!

1. If an error occurs:
An error occurred while trying to set the 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 user name and password (5), so that the system can be automatically run in the future. It is best to use the" system "user, the password can be empty.

This system is very high, higher than your administrator, so you do not want to run the command, this is no hint will be unconditional execution, this permission under your kill core process is OK.

Tips for Windows to execute PHP at timed time

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.