Clear Drupal caches with PHP


• Clear the Drupal 6 & 7 caches with PHP via a small form.
• Drop the following Drupal 6 or 7 PHP in a node or block w/ proper permissions.
• Use at your own risk.



Drupal Clear caches with PHP form.

Drupal 6 cache clear form php:

$output = drupal_get_form('clear_all_cache_myform');
print $output;

function clear_all_cache_myform(&$form_state) {
	$form['submit'] = array('#type' => 'submit', '#value' => t('Clear Caches'));
	return $form;
}

function clear_all_cache_myform_validate($form, &$form_state) {
	//drupal_set_message(t('Your form has been validated.'));
}

function clear_all_cache_myform_submit($form, &$form_state) {
	//  drupal_set_message(t('Your form has been submited.'));
	drupal_flush_all_caches();
	drupal_set_message('I flush the caches boss!');
}

Drupal 7 cache clear form php:

$form = drupal_render(drupal_get_form('clear_all_cache_form'));
print $form;

function clear_all_cache_form($form, &$form_state) {
     $form['submit'] = array(
          '#type' => 'submit',
          '#value' => t('Clear Caches'),
     );
     return $form;
}

function clear_all_cache_form_validate($form, &$form_state) {
     // Validation logic.
     //drupal_set_message(t('Your form has been validated.'));
}

function clear_all_cache_form_submit($form, &$form_state) {
     // Submission logic.
     drupal_set_message('I flush all the caches boss man!', 'status');
     drupal_flush_all_caches();
}
Clear the Drupal 6 caches with PHP via a small form.