Jump to content

Archived

This topic is now archived and is closed to further replies.

ale_jrb

Auto-Updating Database

Recommended Posts

Hi.

I need to write a script that allows a database to automatically update itself even if a user is not there, but I'm not sure how to go about it. Can anyone say?

What I want to happen is something like this:

A user sets something to true in a database (it doesn't really matter how this happens, I'll do that).
The user can then go away, close their browser and end their session, or whatever.
Something in the database updates every now and then (say every 30 seconds).
They come back later, the value having changed.

The best example I can think of is, for example, in online PHP games where you get a mining thing or something and you get some metal whether or not you are at the computer. You can then see how much you have when you come back.

Help? Thanks!

Share this post


Link to post
Share on other sites
You need to setup a cronjpb on your server that makes a call to a PHP script, that then updates the database. You definitely do not want to do it in 30 second intervels though. Especially on shared hosting. I suspect you would get your account suspended. Running your own server perhaps?

Share this post


Link to post
Share on other sites
Yeah, it was just an example. How do you set up one of them?

Thanks.

Share this post


Link to post
Share on other sites
first you write your php script to update the database however you want it to be updated. then you go to cpanel and go to the setup a cronjob icon and the menu is pretty straight forward. you would enter in the path and filename of your script and how often you want it to be ran. the shortest amount of time you can set it for is 1 minute, btw.

Share this post


Link to post
Share on other sites

Not sure what platform you are using but generally a cron job can be set up on a *nix server by using the "crontab" command. Generally "-l" will list all cron jobs and "-e" will allow you to ammend the crontab. An entry would look something like the following:

15 2 * * 2 /usr/bin/php -q /home/webmaster/scripts/newsletter.php

minute, hour, month, day of month, day of week, script

More information on the cron can be found at [a href=\"http://www.adminschoice.com/docs/crontab.htm\" target=\"_blank\"]http://www.adminschoice.com/docs/crontab.htm[/a] or "man crontab".

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.