Jump to content


Photo

Auto-Updating Database


  • Please log in to reply
5 replies to this topic

#1 ale_jrb

ale_jrb
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationLondon, UK

Posted 10 May 2006 - 08:57 PM

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!

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 10 May 2006 - 09:48 PM

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?
PHP Ninja

#3 ale_jrb

ale_jrb
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationLondon, UK

Posted 13 May 2006 - 07:22 PM

Yeah, it was just an example. How do you set up one of them?

Thanks.

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 14 May 2006 - 05:55 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 nfr

nfr
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 14 May 2006 - 02:02 PM


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".

#6 ale_jrb

ale_jrb
  • Members
  • PipPip
  • Member
  • 17 posts
  • LocationLondon, UK

Posted 14 May 2006 - 03:14 PM

OK - thanks very much all!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users