Page 1 of 1
Running a PHP file Automatically
Posted: Sat May 24, 2008 9:29 am
by GoneNuts
Hi people my name is Alan from the UK and I've just about gone nuts

with PHP, new to the forum and to PHP. Only know a little; wondering if any of you people can help me?
I is possible to run a php file automatically on Apache server?
What I would like to do is run a script every day to check records and get averages. Then write the averages into a MySql Data base for later use.
If this is possible when I run these php files on my web server online will it be the same methods and will these type of server side operations eat into my bandwidth?
I would aperciate any Help.
Thanks Alan GoneNuts!
Re: Running a PHP file Automatically
Posted: Sat May 24, 2008 12:44 pm
by califdon
PHP language has no means to execute automatically, but the Linux operating system can run "cron" jobs at specified times, so you can simply set up a cron job to run the PHP script you want, whenever you want. Ref:
http://www.scrounge.org/linux/cron.html
This shouldn't affect your bandwidth, because no requests are being received from "outside", but even if it did, it would be so miniscule, compared to normal web traffic, that you shouldn't worry about it.
Re: Running a PHP file Automatically
Posted: Sat May 24, 2008 3:13 pm
by GoneNuts
Thanks very much for your help califdon making some enquirers now to a few different hosts. What if you was using windows based server is the any way of doing the same thing. I would like to try it on my Apache server on my windows based operating system?
Re: Running a PHP file Automatically
Posted: Sat May 24, 2008 4:41 pm
by Ambush Commander
Windows has Task Scheduler. There are also a number of "cron" services that emulate Unix cron.
Re: Running a PHP file Automatically
Posted: Sun May 25, 2008 6:03 am
by GoneNuts
I have tried Windows Task Scheduler but all it dose is open dreamweaver. It doesn't run the MySQL tasks on the data base which the script has been written for. I don't know how to use Windows Task Scheduler like this. Can you help me? I have wampserve installed with apache I there any of written any commands for apache to run tasks every day?
Re: Running a PHP file Automatically
Posted: Sun May 25, 2008 7:49 am
by vigge89
Set up the scheduled task to run php.exe with the file path to the script you wish ro run as an argument (can't remember the exact syntax for this, try executing php.exe in the windows command line and check the info it provides).
Re: Running a PHP file Automatically
Posted: Sun May 25, 2008 11:19 am
by califdon
GoneNuts wrote:I have tried Windows Task Scheduler but all it dose is open dreamweaver. It doesn't run the MySQL tasks on the data base which the script has been written for. I don't know how to use Windows Task Scheduler like this. Can you help me? I have wampserve installed with apache I there any of written any commands for apache to run tasks every day?
Neither PHP nor Apache have any ability to schedule operations. That is strictly an operating system function. vigge89's method will work, you just need to work out the exact syntax, probably something like:
Code: Select all
php.exe "C:\pathtoscript\yourscript.php"