Results 1 to 3 of 3

Thread: [RESOLVED] PHP Timing & ETC

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Resolved [RESOLVED] PHP Timing & ETC

    Hello again.

    Everyone knows some browser games and there's health, mana or some kind of resources that regenerates themselves automatically in some time. How I can do that in theory? What functions I must exploit to do such a feature? In example I can create a database table for that where I can store my health. I know how to decrease the amount and etc, but what is stable way to make health in database grow. Like increase it by 3 in one minute? I don't think that people will use cron jobs for that, because it will overflow whole server if it requires more execution time, because we have thousands of people to increase the value.

    Well. I don't know how to explain it anymore, but I want it increasing with personal speed of player without taking a care about others. I don't want to do a simple script which increases everything. It must increase the HP with some kind of restoration speed like "3.0" (should be 3.0 per minute) if some player's restoration speed is 5.0 then it should be (5.0 per minute)

    HP: 100/100 = No action
    HP: 99/100 = Tick until 100
    HP: <100 = Tick until 100

    How the heck this is possible

    Thanks.

  2. #2
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: PHP Timing & ETC

    Hi,
    for PHP you can use
    usleep ( int $micro_seconds )
    Code:
    while hp < 100 {
    // wait half a second (500ms)
    usleep(500000);
    hp = hp + 3;
    }
    Its usually not a good idea to delaying any php execution cause it will use more server resources that necessary
    and you may get timeout limits on browser or server you can use javascript settimeout();
    Code:
    setTimeout(function() { alert ("GIVE ME HP"); }, 2000);
    but theres more way to do it like when ever the hp is not 100 call a function get the time and add 3 sec to it ...get time every sec and when the time is equal to the +3 time then add another 3 sec and check it again
    hope u understand the last part
    Last edited by Pc Monk; Apr 24th, 2013 at 04:54 AM.

  3. #3
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: PHP Timing & ETC

    Yeah, you're going to want to handle that logic client side with javascript/JQuery(). I would just initially load the last saved data about the character/environment, update any changes on client side (store in cookies as a error fail-safe) and finally when the user successfully initiates a log off / exit, post back to the server with the new values. Use a public/private key process so people can't simply change the values in the cookie to make themselves have 1,000,000 hp, gold and etc...

    Or... Before and after altercations, post the data back to the server (with the fail-safe still existing in case of connection failure). The less you have to connect, reconnect and connect again to the database and update, the better. You could also use Persistent connections too I guess.

    What ever database/server/client structure you use, implement PDO from the get go.

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width