• Advertisement
Sign in to follow this  

[web] MySQL/PHP based game

This topic is 4147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am designing a game that will be web based, and rely entirely on mysql and php. I'm fine with most of how it will work, but I have one issue. All the world information will be stored in a database, but it will change at regular intervals NOT based on user input. I can easily make php scripts that cause it to change, but I don't know how to run them at certain times. Basically, I want to run some scripts every hour or so that change things around, whether or not people are playing the game or not. Is there a slick way of doing this? Thanks, Rob

Share this post


Link to post
Share on other sites
Advertisement
Cronjob.
http://www.aota.net/Script_Installation_Tips/cronhelp.php3
http://www.2serveu.net/cpanel-tutorials/standardcron.html

Share this post


Link to post
Share on other sites
if you don't have cpanel installed, you can either make a small program to cURL into the script you want, or, you can use the following method

make a script that logs the last time it was hit into (and it was ran).
if (time-delay)>last_ran_time, make this script run the update script (curl is a good choice, here, too).

this script should also have some kind of mutual exclusion system, so it won't be ran twice in the same second. just write something into a file when it starts, and delete it when it ends. this "temporisation" script should die immediately it finds that data written in the file (which would mean another script is running).

you might also want to count how many time your delay has passed since last time the script was "hit". simply substract the last run time from the current time, and run the update script that many times (considering you count in hours, if not, divide to 3600 for unix timestamps).

as long as you'll have visitors, the update script will run constantly :)

izua

Share this post


Link to post
Share on other sites
Also, if you are running windows, you can use the Task Scheduler.

I wrote a pretty walk through on how to set one up quite a few months ago when I first began on my current browser based MMORPG. Mine is nearly done, I've been working on it for about 8 months, and it includes dynamic player maps, so if you need any help let me know.

Oh and if you want the walk through, let me know.

-LABaller

Share this post


Link to post
Share on other sites
There are three methods:

1. Use cron (Or Windows scheduler etc)

Pros: Scheduling is done for you
Cons: Platform-specific to set up, need to track failures etc. Not efficient if running more than a few times an hour. Needs some careful work to ensure that multiple copies never run.

2. Use a continuously running process

Pros: Does exactly what you program it to do- can be efficient even if things happen once a minute or more (doesn't need to reload PHP etc). Schedule can be controlled easily if you make it happen.
Cons: Must be restarted manually following reboot or code redeployment; somewhat tricky to get right.

3. Check the time on some unrelated user activity (e.g. logon), and perform all processing in that web request

Pros: Well, pretty much none- but perhaps simpler for newbies and idiots than the above.
Cons: Everything. Inefficient, error-prone (need to ensure multiple copies don't run, doesn't timeout, handle errors sensibly etc). Delays legitimate user actions. Doesn't run if nobody logged on. etc.

Don't do this.

Mark

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement