Real Effective Time System (PHP) (SOLVED)

C++, C#, Java, PHP, ect...
Post Reply
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Real Effective Time System (PHP) (SOLVED)

Post by vitinho444 »

Ok guys, im here as a desperate game developer!

Since i began working on Browser based games, i faced this problem, How can i make a real effective time system?

So i searched here, googled much and finally i found that function that gets the seconds that passed from 1970 i think.

And i store it on a db, then check if the actual time is bigger 48hours than the db one...
But sadly its not very effective.. :S

I need a time system that can every hour do something, without the need to player being logged in!

If you guys know something please tell me :D

SOLVED

Check this if you want.
Last edited by vitinho444 on Wed Mar 21, 2012 12:34 pm, edited 4 times in total.
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Real Effective Time System (PHP)

Post by Chris »

You have several options. Crontab (http://en.wikipedia.org/wiki/Cron). You could also make a PHP script that will run on you server that loops every 2 days etc:

Code: Select all

while( true )
{
    // do something
    mysql_query("UPDATE `players` SET `turns` = `turns`+1");

    // wait two days
    $twoDays = 60 * 60 * 48; // 172800 seconds
    set_time_limit( $twoDays + 1 ); // add a second to be reduce change of failure
    sleep( $twoDays );
} 
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: Real Effective Time System (PHP)

Post by vitinho444 »

How can i make that script to do something every hour at same time for all players ... ?
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Losdivinos
Posts: 139
Joined: Tue Mar 01, 2011 5:44 pm

Re: Real Effective Time System (PHP)

Post by Losdivinos »

Check if your host has cronjobs enabled. Halls did a great tutorial on this.

http://www.youtube.com/watch?v=uUKWwaqZPy0
Ask me anything about SEO & Marketing.
Skype: rasmus_355
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Real Effective Time System (PHP)

Post by hallsofvallhalla »

I am not sure why you need it to do it if they are logged off. They wont see it anyways. Just have the script check once they log in.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Real Effective Time System (PHP)

Post by Jackolantern »

hallsofvallhalla wrote:I am not sure why you need it to do it if they are logged off. They wont see it anyways. Just have the script check once they log in.
Very true. This one can be hard for new PBBG devs to wrap their heads around. If no one is logged in, nothing has to happen. When someone logs in, you can use the action of them triggering your game's index.php script (or any script you choose to trigger it) to see if the 48-hour or 24-hour script needs to run, and if it does, you can run it. If the players see a time that it ran, you can set the time to be when it would have run (at exactly 24 or 48 hours since its last run). If no one was logged in, they have absolutely no way to know it just happened, and if someone was logged in, their actions would have triggered it. Basically, no one can ever see that it hasn't run.

Using this method will make your game more portable between hosts, and also keeps all the game logic inside your game code, instead of spread around in your game scripts and in the OS' cron scripts.
The indelible lord of tl;dr
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: Real Effective Time System (PHP)

Post by vitinho444 »

SOLVED. THanks
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
Post Reply

Return to “Coding”