开发者

Schedule and execute a PHP script automatically

开发者 https://www.devze.com 2022-12-29 16:09 出处:网络
I have written a PHP script which generates an SQL file containing all tables in my database开发者_如何学C.

I have written a PHP script which generates an SQL file containing all tables in my database开发者_如何学C. What I want to do is execute this script daily or every n days. I have read about cron jobs but I am using Windows. How can I automate the script execution on the server?


You'll need to add a scheduled task to call the URL.

First of all, read up here: MS KB - this is for Windows XP.

Second, you'll need some way to call the URL - i'd recommend using something like wget - this way you can call the URL and save the output to a file, so you can see what the debug output is. You can get hold of wget on this page.

Final step is, as Gabriel says, write a batch file to tie all this up, then away you go.

e: wget is pretty simple to use, but if you have any issues, leave a comment and I'll help out.

ee: thinking about it, you don't even really need a batch file, and could just call wget directly..


add a scheduled task to request the url. either using a batch file or a script file (WSH).

http://blog.netnerds.net/2007/01/vbscript-download-and-save-a-binary-file/

this script will allow you to download binary data from a web source. Modify it to work for you particular case. This vbs file can either be run directly or executed from within a script. Alternately you do not have to save the file using the script, you can just output the contents (WScript.Echo objXMLHTTP.ResponseBody) and utilize the CMD out to file argument:

cscript download.vbs > logfile.log

save that bad boy in a .bat file somewhere useful and call it in the scheduler: http://lifehacker.com/153089/hack-attack-using-windows-scheduled-tasks


Cron is not always available on many hosting accounts.

But try this: http://www.phpjobscheduler.co.uk/ its free, has a useful interface so you can see all the scheduled tasks and will run on any host that provides php and mysql.


You can use ATrigger scheduling service. A PHP library is also available to create scheduled tasks without overhead. Reporting, Analytics, Error Handling and more benefits.

Disclaimer: I was among the ATrigger team. It's a freeware and I have not any commercial purpose.


Windows doesn't have cron, but it does come with the 'at' command. It's not as flexible as cron, but it will allow you to schedule arbitrary tasks for execution from the command line.


Yes, You can schedule and execute your php script on windows to run automatically. In linux like os u will have cron but on windows u can schedule task using task scheduler.


If your code is in remote hosted server then create a cron-job for the same. Else if in local then use a scheduled task in windows.Its easy to implement.I am having servers with so many scheduled tasks running.

0

精彩评论

暂无评论...
验证码 换一张
取 消