search
Homephp教程php手册php:在WINDOWS中设置计划任务执行PHP文件

php:在WINDOWS中设置计划任务执行PHP文件

Jun 13, 2016 am 10:56 AM
phpwindowsTaskexistimplementdocumentplanset up

在网上找了些WINDOWS执行PHP的计划任务的方法,有一个写得很全,可惜在我这竟然没通过。最后不得不综合各门派的方法,才能在我这运行成功。

1、写一个PHP程序,命名为test.php,内容如下所示:


[php]
$fp = fopen("test.txt", "a+"); 
fwrite($fp, date("Y-m-d H:i:s") . " 成功成功了!\n"); 
fclose($fp); 
?> 

$fp = fopen("test.txt", "a+");
fwrite($fp, date("Y-m-d H:i:s") . " 成功成功了!\n");
fclose($fp);
?>程序大胆地写,什么include\require尽管用,都没问题。


      2、新建Bat文件:命名为test.bat,内容如下所示:
D:\php\php.exe -q D:\website\test.php //相应目录自己改上

 


3、建立WINDOWS计划任务:
开始C>控制面板C>任务计划C>添加任务计划
浏览文件夹选择上面的bat文件
设置时间和密码(登陆WINDOWS的)
保存即可了。

 

4、over! 可以右键计划任务点“运行”试试

运行过程省略…………

以上方法有个小问题,计划任务运行的时候,windows桌面会出现dos窗口,在此做些修改。采用vbs的方式实现即可,就不会出现黑色的dos窗口了。代码如下:

DIM objShell
set objShell=wscript.createObject("wscript.shell")
Ireturn=objShell.Run("C:\php\php.exe d:\www\timer.php",0,TRUE)

保存为.vbs文件,替换原来的.bat文件即可。

 


 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software