Date...and stuff

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Date...and stuff

Post by Drachlen »

I'm not sure if this is done with a database or not, so im just going to post here. Im trying to make a count down timer (well it doesnt have to count down, it just needs to count) that counts 30 minutes, then does a task, then repeats. I dont want this to start when the viewer goes to the page, it needs to be something thats constantly going. It doesnt need to be displayed, only the output that it does at 30 minutes (its just going to add 1 to a variable) So if there are any resources on this or if its not too much trouble to write up an example id appeciate it.
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

sounds like you want to set up a script that will run every 30 minutes? youll have to use a non-php program to actually tell php to execute in this manor. i use the windows task scheduler, no clue what the unix/linux couterpart would be.

what you need to do is write a script that will execute everything you want done every 30 minutes. save it. then tell the task scheduler to execute "c:\path to\php.exe c:\path to\script.php" every 30 minutes
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

yes but what if i dont have my computer on? i dont think thats the solution...
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

here's an example of what im talking about:
http://www.couch-fiction.org/

Create an account, click training, and then click one of the stats... It starts a count down timer you can see by refreshing the window..
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

Drachlen wrote:yes but what if i dont have my computer on? i dont think thats the solution...
i meant set this up on your webserver... not your computer.

Ok, here's the thing. Web connections are stateless, as are php pages (for the most part). there is not an easy way to make a php script or a mysql database keep an active timer running that you can fire events on.

on the site that you posted (http://www.couch-fiction.org/), i dont think they are using an active timer. i think they are using a timestamp and a database so when you refresh, it recalculates the time left...

say for example:
i click the button for strength. the server stores a timestamp of when i clicked. everytime i refresh the page, the server takes the timestamp and subtracts it from the current time, and that gives it how long its been since i clicked on the strength button. (this timer is prolly only updated when I refresh, or do something)


If you want something to occur every 30 minutes regardless of who is logged in, you will have to create a script and put it on a timer on your server. if you just want a timer for a user you could use the method with the timestamp and database.
SBukoski
Forum Contributor
Posts: 128
Joined: Wed May 21, 2003 10:39 pm
Location: Worcester, MA

Post by SBukoski »

I think cronjobs do this on Linux servers. I have a few tasks set up as cronjobs that run once a day. All they do is go through the Database and unmark items that were marked as New if they have been there for X number of days. Didn't want this check to occurr everytime someone visited, that would be overkill.
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

Cool man thanks, ive been messin around with the timestamp idea you suggested and now i have a working clock.. I was going to try to give my game its own set of time, every 30 minutes being a 'turn', but i think ill just stick with normal time, and use this timestamp stuff elsewhere
Post Reply