How to implement regular php code execution on a windows Server

Source: Internet
Author: User

This article introduces how to implement any plan in windows and php. If you need it, refer to the following.

1. run PHP regularly!
1. Edit the following code and save it as test. php:

The Code is as follows: Copy code
<? Php
$ Fp = @ fopen ("test.txt", "a + ");
Fwrite ($ fp, date ("Y-m-d H: I: s"). "Let PHP run regularly! N ");
Fclose ($ fp );
?>

Open Text input: D: php4php.exe-q D: php4test. php
Save as. bat format.
D: php4php.exe is the php installation path, and D: php4test. php is the path of the program to be periodically run.

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

3. Set the time to run the task once every one minute and then run the task.

4. Now let's see if the content of the d: php4test.txt file is successful. If the content is as follows, congratulations.

11:08:01 let PHP run on a regular basis!
11:09:02 let PHP run on a regular basis!
11:10:01 let PHP run on a regular basis!
11:11:02 let PHP run on a regular basis!

Ii. make it possible for MYSQL to implement automatic backup!
1. Edit the code below and save it as backup.php. If you want to compress the code, you can copy rar.exe:

The Code is as follows: Copy code

<? Php
If ($ argc! = 2 | in_array ($ argv [1], array ('-- help ','-? '))){
?>
Backup Ver 0.01, for Win95/Win98/WinNT/Win2000/WinXP on i32
Copyright (C) 2000 ptker All rights reserved. This is free software, and you 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 be database name you wowould like to backup.
With the -- help, or -? Options, you can get this help and exit.
<? Php
} Else {
$ Dbname = $ argv [1];
$ Dump_tool = "c: mysqlbinmysqldump ";
$ Rar_tool = "d: php4rar ";
@ Exec ("$ dump_tool -- opt-u user-ppassword $ dbname>./$ dbname. SQL ");
@ Exec ("$ rar_tool a-ag_yyyy_mm_dd_hh_mm mongodbname.rar $ dbname. SQL ");
@ Unlink ("$ dbname. SQL ");
Echo "Backup complete! ";
}
?>

2. Add a task scheduler and enter the following command in step (2:
D: php4php.exe-q D: php4backup. php databasename
3. Set the time to run the task once every day and then run the task.
4. An rarfile consisting of the Database Name and current time will be generated in the d: php4 directory.
5. Congratulations! Success!
Of course, there are many backup methods, so readers can do what they like!

 

The above is the original work. In combination with my own practices, the supplementary instructions are as follows:

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

In the above '"4. next, the system will require the user to set the appropriate user name and password (5), so that the system can automatically run in the future ". it is best to use a "system" user. The password can be blank.

This system has a very high level of permissions, which is higher than your administrator, so you should never mess up when running the command, but if there is no prompt, It will be executed unconditionally, you can kill the core process with this permission.


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.