windows服务器下实现php定时执行代码方法
本文章来介绍一下如何在windows中与php实现任何计划这个东西,有需要的同学可以参考一下下哈。
一、让PHP定时运行吧!
1、 编辑如下代码,并保存为test.php:
代码如下 | 复制代码 |
$fp = @fopen("test.txt", "a+"); fwrite($fp, date("Y-m-d H:i:s") . " 让PHP定时运行吧!n"); fclose($fp); ?> |
打开文本输入:D:php4php.exe -q D:php4test.php
保存为.bat格式。
D:php4php.exe 是php安装路径,D:php4test.php是要定时运行的程序的路径。
2、添加一个任务计划,选择那个.bat文件
3、时间设置为每隔1分钟运行一次,然后运行这个任务。
4、现在我们来看看d:php4test.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:
代码如下 | 复制代码 |
if ($argc != 2 || in_array($argv[1], array('--help', '-?'))) { PHP Shell script for the backup MySQL database. Usage:
|
2、添加一个任务计划,在(如图2所示)这一步输入命令:
D:php4php.exe -q D:php4backup.php databasename
3、时间设置为每天运行一次,然后运行这个任务。
4、最后会在d:php4目录下生成一个以数据库名和当前时间组成的rar文件。
5、恭喜你!大功告成了!
当然备份方式有很多种,读者可按照自己喜欢的去做!
以上是原著.结合本人实贱,补充说明如下:
1. 如果出现错误:
在试着设置任务帐户信息时出现错误
指定的错误是:
0x80070005:拒绝访问
您没有运行所请求的操作的权限
在上面'"4.接下来系统将会要求用户设置适当的用户名及密码(如图5所示),以便系统今后能自动加以运行".这里最好用"system"用户,密码可为空.
这个system的权限非常之高,比你的administrator还要高,所以你在运行命令的时候千万不要乱来,这个可是什么提示都没有就会无条件执行的,这个权限下你kill核心进程都行

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



JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

Why can't my code get the data returned by the API? In programming, we often encounter the problem of returning null values when API calls, which is not only confusing...

Multithreading in the language can greatly improve program efficiency. There are four main ways to implement multithreading in C language: Create independent processes: Create multiple independently running processes, each process has its own memory space. Pseudo-multithreading: Create multiple execution streams in a process that share the same memory space and execute alternately. Multi-threaded library: Use multi-threaded libraries such as pthreads to create and manage threads, providing rich thread operation functions. Coroutine: A lightweight multi-threaded implementation that divides tasks into small subtasks and executes them in turn.

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

Python binary library (.whl) download method explores the difficulties many Python developers encounter when installing certain libraries on Windows systems. A common solution...

Mastering Debian system log monitoring is the key to efficient operation and maintenance. It can help you understand the system's operating conditions in a timely manner, quickly locate faults, and optimize system performance. This article will introduce several commonly used monitoring methods and tools. Monitoring system resources with the sysstat toolkit The sysstat toolkit provides a series of powerful command line tools for collecting, analyzing and reporting various system resource metrics, including CPU load, memory usage, disk I/O, network throughput, etc. The main tools include: sar: a comprehensive system resource statistics tool, covering CPU, memory, disk, network, etc. iostat: disk and CPU statistics. mpstat: Statistics of multi-core CPUs. pidsta
