简体   繁体   English

使用cron作业在localhost上运行php脚本

[英]Run a php script on localhost using cron job

I am trying to set up a cron job on my localhost to call a php script every half an hour 24/7. 我试图在我的本地主机上设置cron作业,以每半小时24/7调用php脚本。 Following are my steps: 以下是我的步骤:

1) I have created a cron.php file to call myscript.php : 1)我创建了一个cron.php文件来调用myscript.php

<?php

echo exec('*/30 * * * * C:\BitNami\wampstack-5.4.21-0\php -f C:\BitNami\wampstack-5.4.21-0\apache2\htdocs\myscript.php');

?>

2) Created a cron.bat file to run the cron.php on browser: 2)创建一个cron.bat文件以在浏览器上运行cron.php

"C:\Program Files\Mozilla Firefox\firefox.exe" "localhost\cron.php"

3) Then I have set up a windows 7 task scheduler to call cron.bat every day. 3)然后,我设置了Windows 7任务计划程序以每天调用cron.bat

I welcome any idea on how to set up a cron job as my approach doesn't do anything. 我欢迎任何关于如何设置Cron工作的想法,因为我的方法无济于事。

Thanks 谢谢

This is not an answer, but only pointers you need to check before you proceed further. 这不是答案,只是在继续操作之前您需要检查的指针。

  1. Crons are available only on unix systems, not windows. Cron仅在UNIX系统上可用,而在Windows上不可用。

  2. While debugging cron or anything similar, schedule them for every minute or (any such acceptable smaller frequency), and once they work every minute, only then schedule them for the original frequencies. 在调试cron或任何类似的东西时,每分钟或每分钟(任何这样的可接受的较小频率)对它们进行调度,一旦它们每分钟工作,就只能对原始频率进行调度。 That will save you some time during debugging. 这样可以节省调试时间。

  3. Its an incorrect call to exec . exec的错误调用。 You don't have to pass all those * in it 您不必通过所有*

  4. Since this is windows, You want to do php.exe and not C:\\BitNami\\wampstack-5.4.21-0\\php -f which would have been done in linux (with proper path) 由于这是Windows,因此您想执行php.exe而不要执行C:\\BitNami\\wampstack-5.4.21-0\\php -f ,而这在linux中已经完成(具有正确的路径)

  5. Your .bat file is currently scheduled daily, you need to schedule it every half hour. 您的.bat文件当前是每天安排的,您需要每半小时安排一次。

dude, you cannot define cron jobs in wamp, the cron is a linux feature and you are running the wamp on windows. 老兄,您无法在wamp中定义cron作业,cron是linux的功能,并且您正在Windows上运行wamp。

you can run the script from the command line (of from cygwin, much better), something like "/php.exe " but you cannot define crons on wamp 您可以从命令行运行脚本(从cygwin,更好),类似于“ /php.exe”,但是您无法在wamp上定义crons

but you can setup the scheduler to run a .bat file that contains the next code cd/ cd "Program Files (x86)" cd GnuWin32 cd bin wget.exe http:// localhost/... (your file) echo DONE 但是您可以将调度程序设置为运行包含下一个代码的.bat文件cd / cd“程序文件(x86)” cd GnuWin32 cd bin wget.exe http:// localhost / ...(您的文件)echo DONE

you don't need to creat .bat file to run php script 您不需要创建.bat文件即可运行php脚本

follow the step to setup cron job for php interpreter.. 请按照以下步骤为PHP解释器设置cron作业。

step 1- Then I have set up a windows 7 task scheduler to call php script by giving path of php interpreter like C:\\xampp\\php\\php.exe filename.php by setting desired interval 步骤1-然后,我设置了Windows 7任务计划程序,以通过设置所需的间隔来指定诸如C:\\ xampp \\ php \\ php.php filename.php之类的php解释器的路径来调用php脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM