Ali Motameni
Ali Motameni

Reputation: 2787

How to Delete some files after Expire time (PHP,MySQL)?

I store some files in a folder and add file_name and expire_time to database.

How to delete files after expire time without running php code continual?

Upvotes: 0

Views: 531

Answers (2)

JerzySkalski
JerzySkalski

Reputation: 624

  1. Use CRON http://en.wikipedia.org/wiki/Cron (simplier version of this service is included to many www hosting offers [it should be in www administration panel - you don't need dedicated server/know linux], but most of them limit CRON to 1 run per hour or even 1 run per day).
  2. To your main site index.php include code that get from database files that expired and remove them. This method does not require CRON, but uses much more resources and may not work if your site is not popular [delete one time per day? week?].

Upvotes: 2

YyYo
YyYo

Reputation: 641

Like @JerzySkalski first recommend, use CRON for your task. Its the simplest yet robust way to do it.

others may advice you to create a deamon for it, which in IMO its overkill for your task.

Cheers

Upvotes: 0

Related Questions