Home >Backend Development >PHP Tutorial >Windows scheduled execution of PHP skills, windowsphp skills_PHP tutorial

Windows scheduled execution of PHP skills, windowsphp skills_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:54:531083browse

Techniques for regularly executing PHP on windows, Windowsphp tips

I believe that many readers (PHP enthusiasts) often complain during the process of work and study: how to do it in WIN How to let PHP automatically send emails at regular intervals? ? How to make MYSQL realize automatic backup without worries? ? Of course it can be done entirely manually, but the operation seems a bit too cumbersome! Don't worry, this problem can be easily solved by using the system's task scheduler (called a scheduled task in Windows 98). This feature is often overlooked or never thought of by many users :).

The so-called task plan is for the computer to automatically call the application program set by the user in advance, thereby simplifying the user's operation. Using the task scheduler of Windows 2000 (equivalent to the cron program under *NIX, which will not be described in detail here), we can schedule any script, program or document to run at the most appropriate time to meet our needs. The following takes Windows 2000 as an example.

Specifically, if we need to use the task scheduler to run automatically, we should perform the following steps:

1. Click the "Start" button, and then select "Programs" → "Accessories" → "System Tools" → "Task Schedule" (or "Settings" → "Control Panel" → "Task Schedule") to start the Windows 2000 task schedule management program.

2. Double-click the "Add Task Plan" icon in the "Task Plan" window to start the system's "Task Plan Wizard", then click the "Next" button and select the desired program from the given program list. Automatically run the application and click the "Next" button.
Set an appropriate task schedule name and select the time frequency to automatically perform this task (such as daily, weekly, monthly, one-time, every time you start the computer, every time you log in, etc.), then click "Next" " button.
At this time, the system will ask the user to set the specific time for the program to run, such as what day, what time, what time period it can run, etc. We only need to set it according to our own needs.

4. Next, the system will ask the user to set an appropriate username and password so that the system can run automatically in the future.

5. Finally, we only need to click the "Finish" button to add the corresponding task to the Windows 2000 task scheduler. After that, it will automatically "remember" the task once the system time and If the relevant conditions match the plan set by the user, it will automatically call the application specified by the user, which is very convenient (every time you start Windows 2000, the task scheduler will automatically start and run in the background to ensure that the user's plan can be scheduled on time. implement).

Now let's test whether the task we just created is successful. Right-click the "php" program icon (as shown in Figure 6) and select "Run" in the pop-up menu. Under normal circumstances, the program icon can start normally as long as it is activated in this way. If the operation fails, you can check whether the user and password are set correctly, and confirm whether the "Task Scheduler" service has been started. I turned it off in order to save system resources, which caused the operation to fail, which cost me a long time to find. In addition, you can also check the "system log" to see what caused the operation to fail.

Okay, after talking about so many tasks planning applications, let’s get to the point. Two examples will be introduced below:

1. Let PHP run regularly!
1. Edit the following code and save it as test.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 in .bat format.
D:php4php.exe is the php installation path, and D:php4test.php is the path of the program to be run regularly.

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

3. Set the time to run every 1 minute, and then run the task.

4. Now let’s see if the content of the d:php4test.txt file was successful. If the content is as shown below, congratulations on your success.

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

2. Make automatic backup possible for MYSQL!
1. Edit the following code and save it as backup.php. If you want to compress it, you can copy a rar.exe:
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. http://www.dareng.com
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:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1118330.htmlTechArticleTips for windows to execute PHP regularly, windowsphp techniques for windows to execute PHP regularly. I believe many readers (PHP enthusiasts) are working , I often complain during the learning process: How to make PHP automatically schedule in WIN...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn