4

Drupal 7 comes with some files (authorize.php, cron.php, update.php, xmlrpc.php) that bootstrap Drupal, and execute specific tasks.

Are there any cases where a module would need a similar file to bootstrap Drupal, and execute specific tasks? What are the pros of using this method instead of using a menu callback?
Why does Drupal use cron.php, but it uses a menu callback for the batch operations?

2

Take a look at the discussion on this question What's the fastest method/implementation for an Ajax callback?

It shows that you can sidestep (or partially sidestep) index.php for performance reasons. This is unlikely to be a whole page, but perhaps a module specific ajax lookup.

Doing so carries potential security risks and compatibility risks so should only be done so in cases where you really need it to be fast and you don't need the flexibility that a normal menu callback will allow.

2

If you examine these files you will see that they share the bootstrap process, but the rest is different.

index.php calls menu_execute_active_handler, which is a fairly heavyweight function. It essentially does everything to render a page (lots of hooks get called).

cron.php just calls drupal_cron_run, which is fairly lightweight (it just calls everything that implements hook_cron and also bumps up the execution time via set_time_limit. This can decrease the memory footprint for expensive tasks (like rebuilding search indexes).

Addendum to address comment

Routing everything through index.php is good (front controller pattern). However, I see it being acceptable to have an extra script entry point for maintenance tasks that essentially run a single hook. I think of this as tasks that could normally be handled by drush, but need to be web-accessible or if a site doesn't have CLI capabilities. I have also run into a few cases where a site would bootstrap, but abort because of major problems (like a severely damaged menu cache). A maintenance script can fix this, if drush can't be used. It is worth noting, though, that extra precaution needs to be taken to lock down the scripts against malicious access and use.

  • Taking your example of expensive tasks, Drupal doesn't have a search.php file. If Drupal doesn't use such file, why would a third-party module use a similar file? – kiamlaluno May 11 '11 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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