Page 1 of 1

Is it possible?

Posted: Mon Feb 21, 2005 9:58 pm
by Dale
I'm sorry if this is posted in the wrong room...

Is it possible for a PHP script to update the database every 'x' amount of minutes without someone actually viewing that page?

Posted: Mon Feb 21, 2005 10:09 pm
by feyd
yes. It's called 'cron' usually.


Moved to PHP - Code.

Posted: Mon Feb 21, 2005 10:35 pm
by magicrobotmonkey
not php directly, but you can set up a cron job which will run a specified script every specified time amount. Unless you're on a windows server.

Posted: Mon Feb 21, 2005 10:37 pm
by feyd
Cron can be done on Windows.. under Scheduled Tasks.

Posted: Tue Feb 22, 2005 5:39 am
by Chris Corbyn
Yup.. I have a cron job running on windows to syncronise a remote mysql db with an access one on my local machine...

(Set this up a while ago and since discovered myodbc :( )

Just schedule "php.exe yourscriptname.php" every 5 mins or whatever.

Posted: Tue Feb 22, 2005 6:50 am
by Dale
Ahhh... i wanted something that will update without any assitance, as i am using a hosting package... so i cannot control 'php.exe'. I might just have it update whenever i click a button.

Thx anyways :)

Posted: Tue Feb 22, 2005 6:59 am
by Chris Corbyn
Just a thought but u could bury it into the homepage of your website or whatever so your visitors do the work "blindly" for you.

They don't see what happened on the server when they requested your web page but your db gets updated (of course... you need enough visitors for it to be effective and you'd have to cut out all the errors in case of db failures and users getting 'mysql connect failed... bla bla bla')

Or you can just have a page open that refreshes or redirects to itself very x minutes

Posted: Tue Feb 22, 2005 9:48 am
by Dale
Ahhh, i've jsut found cronjobs in cPanel... i could use that. However the idea of users doing the updated via an invisible iframe or something sounds much better.

Posted: Tue Feb 22, 2005 9:53 am
by feyd
provided there is no visible output (or you capture it and toss it) you can just include it in the page code like d11wtq was getting at. No need for an iframe, or any "special" trickery for the user's involvement.

Posted: Tue Feb 22, 2005 5:38 pm
by pickle
There are pros and cons to putting the updating hidden inside your homepage.

Pro:
The DB only gets updated when it needs to be. There's no sense updating it every 5 minutes if no one's looking at the changes

Con:
Attaching the work to a page load will increase the load time of the page. Depending on how much data there is to crunch, and how busy the server is, this could add up.

One solution may be to just do the work for the first page load of the hour. So, if someone doesn't look at your page until 9:35, that's the page that does the work. Everyone else looking at the page that hour won't have to wait for the DB to be synched.