Long story short, is there a correct way to override DRUPAL_MAXIMUM_TEMP_FILE_AGE?

I'm working on testing a fix to a module I wrote a while back that handles some uploaded files. I neglected to call file_usage_delete and set file_managed status to 0. To test my changes more quickly, I'd like to schedule files for deletion after doing some operations on them. To do this reasonably I had to reduce the turn around time on deletions to something on the order of minutes than hours. I went ahead and edited system.module where DRUPAL_MAXIMUM_TEMP_FILE_AGE is defined as 6 hours, but the comments immediately preceding the defines indicate:

@file Configuration system that lets administrators modify the workings of the site.

I checked the places where this value is used, and it doesn't look to be actually configurable besides editing system.module directly. Maybe I'm missing something?

Is there a correct way to set this that doesn't involve "hacking core"?

1 Answer 1


It isn't configurable. You would be better served writing your own routine that executes on a regular interval and searches for temporary files whose creation age is greater than 10 minutes ago.

The DRUPAL_MAXIMUM_TEMP_FILE_AGE constant is specifically intended to inform Drupal on when a file that has not yet been set to permanent should be removed.

If you take a look at system.module, the relevant code is contained in a hook_cron() implementation. The code reads:

  $result = db_query('SELECT fid FROM {file_managed} WHERE status <> :permanent AND timestamp < :timestamp', array(
    ':permanent' => FILE_STATUS_PERMANENT,

My recommendation is to simply implement your own hook_cron() and use the same code, but calculate for files older than 10 minutes.

You will also need for cron to execute on a 10 minute interval. For this, you'll need to add a crontab and install either ultimate_cron or elysisia_cron. I prefer ultimate_cron.

Please see my answer to this question for more information on setting up crontab on a 60 second interval for maximum timeliness. You'll then use elysia_cron or ultimate_cron to control the actual job execution interval.

  • As an aside: Drupal's codebase is typically intended to serve as a demonstration of best practices and the "Drupal way," so copying the patterns established by Drupal will usually be your best bet.
    – Beau
    Dec 23, 2020 at 19:37
  • Thanks Beau for taking the time to answer. Long story short, the answer is "No", which is what I figured. This was more of a curiosity for me, the code comment about system.module being a "configuration system" is misleading. I did find that usage of DRUPAL_MAXIMUM_TEMP_FILE_AGE, which lead me to believe it wasnt actually configurable. Outside of testing, the 6 hour deletion schedule will be adequate.
    – Pete
    Dec 23, 2020 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.