windows定时执行PHP的技巧,windowsphp技巧
windows定时执行PHP的技巧,windowsphp技巧
windows定时执行PHP相信不少读者(PHP爱好者)在工作、学习的过程中经常抱怨:在WIN如何让PHP定时自动发信呢??如何让MYSQL实现自动备份而无后顾之忧呢??如 果完全依靠手工进行当然也可以实现,但操作上似乎过于繁琐了一点!别着急,利用系统的任务计划程序(Windows 98称之为计划任务)可轻易解决这一问题。这一功能往往被很多用户忽略或者未曾想到:)。
所谓任务计划就是由计算机自动调用用户事先设置好的应用程序,从而达到简化用户操作的目的。利用Windows 2000的任务计划程序(相当与*NIX下的cron程序,这里不再对其详述),我们可以安排任何脚本、程序或文档在最恰当的时候运行,从而满足自己的需 要。下面以Windows 2000为例。
具体来说,我们若需利用任务计划程序自动运行则应执行如下步骤:
1.单击“开始”按钮,然后依次选择“程序”→“附件”→“系统工具”→“任务计划”(或者是“设置”→“控制面板”→“任务计划”),启动Windows 2000的任务计划管理程序。
2.在“任务计划”窗口中双击“添加任务计划”图标,启动系统的“任务计划向导”,然后单击“下一步”按钮,在给出的程序列表中选择需要自动运行的应用程序,然后单击“下一步”按钮。
设置适当的任务计划名称并选择自动执行这个任务的时间频率(如每天、每星期、每月、一次性、每次启动计算机时、每次登录时等),然后单击“下一步”按钮。
此时系统将会要求用户对程序运行的具体时间进行设置,如几号、几点钟、哪几个时间段才能运行等,我们只需根据自己的需要加以设置即可。
4.接下来系统将会要求用户设置适当的用户名及密码,以便系统今后能自动加以运行。
5.最后,我们只需单击“完成”按钮即可将相应任务添加到Windows 2000的任务计划程序中,此后它就会自动“记住”这个任务,一旦系统时间及相关条件与用户设置的计划相符,它就会自动调用用户所指定的应用程序,十分方 便(每次启动Windows 2000的时候,任务计划程序都会自动启动,并在后台运行,确保用户的计划能够按时执行)。
现在我们来测试一下刚才所建的任务是否成功,鼠标右键单击“php”程序图标(如图6所示),在弹出的菜单里面选择“运行”。一般情况下程序图标只要这样 激活运行就可以正常启动。如果运行失败可查看用户和密码是否设置正确,还有确定“Task Scheduler”服务是否已启动,本人当初就是为了节省系统资源把它关掉了导致运行失败,害我找了大半天。另外也可从“系统日志”里查看到底是什么原 因造成运行失败的。
好了,讲了这么多任务计划的应用,现在我们切入正题,下面将介绍两个例子:
一、让PHP定时运行吧!
1、 编辑如下代码,并保存为test.php:
$fp = @fopen("test.txt", "a+");
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文件的内容时候是否成功。如果内容为如下所示,那么恭喜你成功了。
2016-03-03 11:08:01 让PHP定时运行吧!
2016-03-03 11:09:02 让PHP定时运行吧!
2016-03-03 11:10:01 让PHP定时运行吧!
2016-03-03 11:11:02 让PHP定时运行吧!
二、让MYSQL实现自动备份变成可能!
1、编辑如下代码,并保存为backup.php,如果要压缩可以拷贝一个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:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Pagoda Panel is a very excellent server management panel under Linux system. It has powerful functions and friendly interface, which can help users manage servers easily. In the process of using the Pagoda Panel, it is sometimes necessary to limit the speed of the virtual host to ensure the stability and fluency of the server. This article will introduce how to set the speed limit of the virtual host through the Pagoda panel to achieve a good user experience. 1. Overview of Speed Limit Speed limit refers to limiting the host bandwidth and ensuring the normal operation of the server by controlling the host traffic. exist

The Gin framework is a lightweight web framework that provides the basic functionality needed to quickly build web applications. The Gin framework is flexible, efficient, and scalable, so it is widely used in the Internet field. Among them, the virtual host and domain name binding functions of the Gin framework are important features that other web frameworks do not have. This article will introduce this function in detail. 1. What is a virtual host? A virtual host creates multiple independent and mutually isolated virtual hosts on a physical host. Each virtual host has its own unique

Foreign free php virtual hosts include DreamHost, Bluehost, Hostinger, 000Webhost, FreeHostia, Zymic, ByetHost and SiteGround.

In the Internet age, web hosting is a very popular service that allows users to own their own website and manage it easily. However, when using virtual hosts, security issues must also attract our attention. In response to this situation, Pagoda Panel provides a good solution that can help us better protect the security of the virtual host. This article will introduce how to use the Pagoda panel to protect the security of virtual hosts. 1. Set the login password and port. Before using the Pagoda panel, the first step is to set a secure login password. default

How PHP connects to Tencent Cloud Server ECS to implement cloud virtual host deployment Introduction: With the rapid development of cloud computing, more and more enterprises and developers choose to deploy applications to cloud servers to obtain better elasticity and security. and scalability. This article will introduce how to use PHP to connect with Tencent Cloud Server ECS (Elastic Compute Service) to implement cloud virtual host deployment. Step 1: Create a Tencent Cloud Server ECS instance. First, we need to

How Nginx implements domain name-based virtual host configuration requires specific code examples. Nginx is a high-performance HTTP and reverse proxy server that provides flexible configuration options to implement domain name-based virtual host configuration. In this article, we will introduce in detail how to configure Nginx to implement domain name-based virtual hosting and provide specific code examples. First, we need to add the virtual host configuration block to the Nginx configuration file. On Ubuntu systems, the default configuration file path is /et

How to use Nginx to implement virtual host configuration based on domain name and path Introduction: In network application development, it is often necessary to configure multiple virtual hosts to provide different services. Nginx is a high-performance HTTP and reverse proxy server. By using Nginx, we can easily implement virtual host configuration based on domain name and path. This article will introduce how to use Nginx to implement such a configuration and give corresponding code examples. 1. The virtual host based on the domain name is configured in the Nginx configuration file, using

Nginx virtual host optimization configuration to improve website performance and user experience Introduction: Nowadays, with the continuous development of the Internet, the number of visits to the website is also increasing. As the entrance to the website, the optimized configuration of Nginx plays a crucial role in improving website performance and user experience. This article will introduce some methods for optimizing the configuration of Nginx virtual hosts, along with code examples so that you can better understand and apply them. 1. Configuration of virtual host Virtual host is an important concept in Nginx. Through the configuration of virtual host, we can
