Running a PHP file Automatically

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
GoneNuts
Forum Newbie
Posts: 8
Joined: Sat May 24, 2008 9:18 am

Running a PHP file Automatically

Post by GoneNuts »

Hi people my name is Alan from the UK and I've just about gone nuts :crazy: 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? :banghead:

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? :mrgreen:

I would aperciate any Help.

Thanks Alan GoneNuts!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Running a PHP file Automatically

Post 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.
GoneNuts
Forum Newbie
Posts: 8
Joined: Sat May 24, 2008 9:18 am

Re: Running a PHP file Automatically

Post 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?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: Running a PHP file Automatically

Post by Ambush Commander »

Windows has Task Scheduler. There are also a number of "cron" services that emulate Unix cron.
GoneNuts
Forum Newbie
Posts: 8
Joined: Sat May 24, 2008 9:18 am

Re: Running a PHP file Automatically

Post 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?
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Re: Running a PHP file Automatically

Post 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).
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Running a PHP file Automatically

Post 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"
Post Reply