Jump to content

PHP Timers


Gex

Recommended Posts

Now I always seem to have trouble when it comes to PHP time functions and timers. They never seem to want to work for me. So basically, I have a system that records details on a user. It records a timer in seconds when the user clicks a link.

$timer = time() + 600;

I then place this directly into the databse, so it will be in seconds like this.. 1203435485735. So I go to my main config file and start to make the function that I need to check when those 10 minutes are up and then set another 10 minutes and do something.And this is where I get stumped.. I get something like.

if($pid['job'] == 1){$timer = $job['timer'] - time();if(timer() >= $timer){Do FUNCTION }}

No matter what I try to do the timer just doesn't work at all. I am problem doing something wrong as I said timers ain't my thing. But any help would be appreciated.

Link to comment
Share on other sites

You might be better off checking the time of the next request.Rather than using the idea of a timer, think about using elapsed time. For example, save the time of the first request in a session variable, then compare it to the time of the next request. If it is greater than 10 minutes - act accordingly.

Link to comment
Share on other sites

Thanks for the reply.. i'll give that shot. But wouldn't setting that into a SESSION variable just stop working after the user leaves the webpage. I would liek to have it run even if they are not on the webpage.

Link to comment
Share on other sites

maybe you should explain it some more. I don't think a database is going to be able to store a function like that. What's the point of having the timer run if the user has left the page? What exactly do you want to happen?

Link to comment
Share on other sites

maybe you should explain it some more. I don't think a database is going to be able to store a function like that. What's the point of having the timer run if the user has left the page? What exactly do you want to happen?
Right in my script the user has selected a job, and the job pays out money into their account every 24 hours (I placed it at 1 min for testing purposes) I would like this to still run even when the user has left the site. So every 24 hours whether the user is logged on or not they will get the income from the database that their job specifies into there account. If you catch what I mean.
Link to comment
Share on other sites

You should use a cron job, which will call your PHP script every 24 hours.
Hmm I am not familar with cron... i'll look into it.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...