How to run a php function in the specified date ?

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
User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

How to run a php function in the specified date ?

Post 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
User avatar
DaveTheAve
Forum Contributor
Posts: 385
Joined: Tue Oct 03, 2006 2:25 pm
Location: 127.0.0.1
Contact:

Post 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]
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post 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,
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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)
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post 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 :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Click.

Thanks :)
User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

Thanks

Post by christian_phpbeginner »

Hi folks, thanks a lot, but the question is where to put the function ? Thank you !
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

Post by christian_phpbeginner »

Thanks for the replies, guys !
Post Reply