Jump to content

[Beginner] Timers in PHP?.


ChrisMartino

Recommended Posts

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?.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.