scheduling the server to do updates/jobs
<offtopic>This community looks great and its my first topic so I should at least say I entered here because I've recently started to become more and more into web programming and decided to create an online game. Right now I'm digging all around the web to find things to start with. I have basic PHP & MySQL knowledge (and good Java and C), but that's why I want to learn along the way as I'm making something..
So, what I'm trying to make is a game similar to Cybernations, Travian and Hattrick, with ideas and concepts from many other games but brought online, in-browser.</offtopic>
The question that bugs me lately is: how will I make the server update itself (scheduled updates and scheduled script running, say from 10 to 10 hrs or something like it).
For example, as an exercise - say I'm making a page which I want from 5 to 5 minutes to update itself with some text (automatically, by the server). for ex:
i upload the page on a free hosting service with php and mysql - like FreeHostia
now the page is blank ..
//after ~12 minutes it shows up:
5 minutes passed! update 
5 minutes passed!
I hope you get it, I want to know how can I configure a server / a hosting service / everything , to run scripts on a scheduled time (scripts to update a db, process some algorithms etc). I need something I can start studying on.
Thanks in advance
You need to look into Cron Jobs I think.....
Yay! Cron Jobs got it done for me, found a nice service setcronjob.com which I can use to schedule updates on my free hosting server :) Thanks.
Alternative 5 minute cron job
if you are going to use a 5 minute cron job, make sure it is not going to start taking a long time when the amount of data you have increases.
If the 5 minute cron is updating members then you should consider an alternative way:
On your members table (or a OneToOne table for the members table; members_resets) add a new field named something like: last_5min_reset with a type of unsigned int(10).
When a member is first registered set this to the current time using the time() function.
In your header.php or the place where your code is run before the action code you will need the following code:
I have found that I need to run this script before fights/battles in order to make it seem like the defending member is up to date with the resets. So I simply delegated the functionality to a function and made it possible to be used for any member and then updated the appropriate member that the function was called for.
If this isn't what you wanted I'm sure it is what someone else wanted and therefore anyone who may come across this now or in the future should find it useful.
|All times are GMT. The time now is 05:02 AM.|
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0