ale_jrb Posted May 10, 2006 Share Posted May 10, 2006 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! Quote Link to comment Share on other sites More sharing options...
Caesar Posted May 10, 2006 Share Posted May 10, 2006 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? Quote Link to comment Share on other sites More sharing options...
ale_jrb Posted May 13, 2006 Author Share Posted May 13, 2006 Yeah, it was just an example. How do you set up one of them? Thanks. Quote Link to comment Share on other sites More sharing options...
.josh Posted May 14, 2006 Share Posted May 14, 2006 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. Quote Link to comment Share on other sites More sharing options...
nfr Posted May 14, 2006 Share Posted May 14, 2006 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.phpminute, hour, month, day of month, day of week, scriptMore 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". Quote Link to comment Share on other sites More sharing options...
ale_jrb Posted May 14, 2006 Author Share Posted May 14, 2006 OK - thanks very much all! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.