Page 1 of 1

How to run a php function in the specified date ?

Posted: Thu Jan 11, 2007 6:26 am
by christian_phpbeginner
Hey folks,

I am hosting my web at http://www.ueuo.com, but the problem is that it is only limited to 200MB. Somehow, I am letting my user to contact me, and then again. Because it's only limited to 200mb, I want to create a function that deletes all emails after 48 hours, automatically. Now, I can create the function but don't know how to execute and where to put it ??

Thanks a lot,
Chris

Posted: Thu Jan 11, 2007 7:12 am
by DaveTheAve
pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[syntax="php"]
$offset = 172800; //60secs * 60 Minutes * 24 hours * 2 Days
if($emails[$i]['timestamp'] < (time()-$offset)) {
   //Delete Email
}
Understand?


pickle | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Jan 11, 2007 7:57 am
by impulse()
DaveTheAve wrote:$offset = 172800; //60secs * 60 Minutes * 24 hours * 2 Days
if($emails[$i]['timestamp'] < (time()-$offset)) {
//Delete Email
}

Understand?
I may not fully understand so don't be offended by my questioning - But doesn't you code say that if the e-mails time stamp is below 48 hours then it deletes the e-mail?

Regards,

Posted: Thu Jan 11, 2007 8:19 am
by volka
impulse() wrote:But doesn't you code say that if the e-mails time stamp is below 48 hours then it deletes the e-mail?
If it is smaller than "now minus 48 hours" (time()-$offset)

Posted: Thu Jan 11, 2007 8:29 am
by impulse()
volka wrote:
impulse() wrote:But doesn't you code say that if the e-mails time stamp is below 48 hours then it deletes the e-mail?
If it is smaller than "now minus 48 hours" (time()-$offset)
I may have not woken up fully yet but doesn't that say that the e-mail is not older than 48 hours, meaning the e-mail shouldn't be deleted?

Yet again, sorry if I'm being obtuse, I just hate not understanding something :)

Posted: Thu Jan 11, 2007 8:37 am
by volka
No. time()-172800 means "The timestamp as it was 172800 seconds, 48 hours, ago"
if the timestamp of the email is smaller it's even longer ago.

Posted: Thu Jan 11, 2007 8:45 am
by impulse()
Click.

Thanks :)

Thanks

Posted: Fri Jan 12, 2007 2:09 am
by christian_phpbeginner
Hi folks, thanks a lot, but the question is where to put the function ? Thank you !

Posted: Fri Jan 12, 2007 10:02 am
by pickle
Some hosts allow you to set up cron jobs - automatic script execution at a pre-defined, recurring time. You could put this function in a script, then call that script in a cron job. Ask your host about cron jobs.

Posted: Fri Jan 12, 2007 12:02 pm
by christian_phpbeginner
Thanks for the replies, guys !