ChrisMartino Posted October 3, 2009 Share Posted October 3, 2009 Hey I'm curious, I would like to do a timer in PHP, like for periods of 1 Month and be able to reset the timer ect and when the time runs out be able to delete a certain DIR, For example: Time set, 1 Month, 1 Month ended, Deletes DIR "/home/users/server100" And how would i go about adding time to it for example if someone had 10 days left on the timer and wanted to add 15 more days, How would i do this?. Quote Link to comment https://forums.phpfreaks.com/topic/176334-beginner-timers-in-php/ Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Simple answer is you can't what your describing is essentially impossible. PHP is serverside code, the only time the code is 'active' is during the time it takes for a request to come from a user, for the PHP engine to parse through a file and send the output. There are certain workarounds that could be used. For example some servers have CRON jobs installed, which would allow a script to run at specified periods. So daily/hourly etc (I believe you can do hourly, not sure how quick you can set it too as I've never used it). Alternatively you could only update the timer when the user views your site. So if you wanted to delete a file at the end of the period, and that period ended three days ago. The next time the user logs in after the deadline is passed the file is deleted then. With regards to adding time, controlling time or whatever, a database of flatfile system is how you'd control it, with MySQL being the most likely/obvious solution. Basically if you've not worked out what I'm saying by now... It all depends on what you have in mind. It almost sounds like your after creating a deadmans switch. What I mean is to have a script that if it's not accessed within a certain number of days, it delete a specified file/folder. But that could just be my imagination. Quote Link to comment https://forums.phpfreaks.com/topic/176334-beginner-timers-in-php/#findComment-929402 Share on other sites More sharing options...
Alex Posted October 3, 2009 Share Posted October 3, 2009 the only time the code is 'active' is during the time it takes for a request to come from a user, for the PHP engine to parse through a file and send the output. That's not exactly accurate. PHP can be complied into stand-alone applications with things like Roadsend compile, PriadoBlender, etc.. Quote Link to comment https://forums.phpfreaks.com/topic/176334-beginner-timers-in-php/#findComment-929409 Share on other sites More sharing options...
cags Posted October 3, 2009 Share Posted October 3, 2009 Well I wasn't aware that was possible. But in either case, I highly doubt it's what the OP was after with the fact the first word in the subject is Beginner, not to mention I'd have thought if you wanted a standalone application you'd be better off using another language (personal opinion). Quote Link to comment https://forums.phpfreaks.com/topic/176334-beginner-timers-in-php/#findComment-929577 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.