Jump to content

Auto-Updating Database


ale_jrb

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!
Link to comment
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?
Link to comment
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.
Link to comment
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".
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.