Page 1 of 1
Real Effective Time System (PHP) (SOLVED)
Posted: Sat Jan 28, 2012 4:06 pm
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
SOLVED
Check this if you want.
Re: Real Effective Time System (PHP)
Posted: Sat Jan 28, 2012 5:11 pm
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 );
}
Re: Real Effective Time System (PHP)
Posted: Sat Jan 28, 2012 5:35 pm
by vitinho444
How can i make that script to do something every hour at same time for all players ... ?
Re: Real Effective Time System (PHP)
Posted: Fri Mar 16, 2012 6:18 pm
by Losdivinos
Check if your host has cronjobs enabled. Halls did a great tutorial on this.
http://www.youtube.com/watch?v=uUKWwaqZPy0
Re: Real Effective Time System (PHP)
Posted: Mon Mar 19, 2012 3:16 pm
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.
Re: Real Effective Time System (PHP)
Posted: Tue Mar 20, 2012 5:15 pm
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.
Re: Real Effective Time System (PHP)
Posted: Wed Mar 21, 2012 12:31 pm
by vitinho444
SOLVED. THanks