background image

fwrite($fp, date("Y-m-d H:i:s") . " 让 PHP 定时运行吧!\n");
fclose($fp);
?>
打开文本输入:D:\php4\php.exe -q D:\php4\test.php
保存为.bat 格式。
D:\php4\php.exe 是 php 安装路径,D:\php4\test.php 是要定时运行的程序的路径。

2、添加一个任务计划,选择那个.bat 文件

3、时间设置为每隔 1 分钟运行一次,然后运行这个任务。

4、现在我们来看看 d:\php4\test.txt 文件的内容时候是否成功。如果内容为如下所示,那么
恭喜你成功了。

2003-03-03 11:08:01 让 PHP 定时运行吧!
2003-03-03 11:09:02 让 PHP 定时运行吧!
2003-03-03 11:10:01 让 PHP 定时运行吧!
2003-03-03 11:11:02 让 PHP 定时运行吧!

二、让 MYSQL 实现自动备份变成可能!

1、编辑如下代码,并保存为 backup.php,如果要压缩可以拷贝一个 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) 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 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!";
}
?>