Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   PHP browser game resource question (http://www.programmingforums.org/showthread.php?t=15861)

Apophis May 22nd, 2008 5:17 PM

PHP browser game resource question
 
How could i make a php browser game add resources on to every player per minute or hour.
So if they had money as a resource. how could i make it so that every hour they get 5 more money or something like that.

Thank you
Apophis.

Sane May 22nd, 2008 5:39 PM

Re: PHP browser game resource question
 
In general, there are two ways to do this:
  1. Set a cron job on your server to run a php script every 60 minutes which adds resources to all players.

    Advantages:
    • Easy to code
    • Very extendable

    Disadvantages:
    • If your server goes down during the time the cron job should occur, everyone misses the update
    • Not portable between all servers
    • Requires some degree of maintenance
    • Server stress is less uniformly distributed (peaks every hour)


  2. In every location where a user could possibly see someone's gold (or resources, or whatever you need to update), call a common function which checks how many hours ago the last update for this player was. Then make a number of updates equal to the amount of hours passed.

    Advantages:
    • Better integrated with the rest of your code
    • Becomes very simple to code if you already have a common function that returns the amount of gold someone has (simply place the check inside the common function)
    • Portable between all servers
    • Updates will still occur even if the server goes down momentarily
    • Server stress is more uniformly distributed (no abnormal peaks)

    Disadvantages:
    • Often more difficult to code
    • Potentially buggy if not done correctly
    • Any bugs can lead to very bad exploits and even necessary database restorations

Picking your weapon will completely depend on the server you're running, your long term plans for the project, and the amount of time and effort you want to commit.

Apophis May 22nd, 2008 6:15 PM

Re: PHP browser game resource question
 
A cron job sounds the best but how could i set one up?

Sane May 22nd, 2008 7:24 PM

Re: PHP browser game resource question
 
You will have to check your hosting plan's FAQ or talk to customer support. If they are a good hosting service, they should give you some from of cron setup in your control panel. If you're on a $3/month plan, then it's not so likely.

Apophis May 23rd, 2008 12:32 AM

Re: PHP browser game resource question
 
Thank you- i have now set one up


All times are GMT -5. The time now is 4:22 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC