Drupal - How do I call the menu_rebuild function in Drupal 7?
Drupal 7
If you're using drush, you may run:
drush eval 'menu_rebuild();'
If won't work, see: How to do menu rebuild when having PHP Fatal error?
Drupal 6
drush php-eval 'drupal_rebuild_theme_registry()'
memcached
If you're using memcached, you've to restart it.
On Linux: /etc/init.d/memcached restart
On OS X (if using Homebrew): brew services restart memcached
Open the database schema, then delete all contents of menu_links and menu_router tables with the following SQL queries:
DELETE FROM menu_links;
DELETE FROM menu_router;
Then run http://example.com/update.php. It will call menu_rebuild(), which will populate these tables with 'fresh' data. It worked for me after a "PHP Fatal Error: Out of memory" turned some of my menus into a mess.
But be aware, that it will wipe out all you custom menus which you will have to rebuild manually. To avoid it you may play a bit with deleting of some selected records from menu_router and menu_links, but for me it didn't work well.
And don't forget to back-up your database and site directory before deleting contents from the tables.
Create a file with the following content and simply drop in the Drupal root directory. Let's say menu-rebuild.php
. Run it http://example.com/menu-rebuild.php
<?php
error_reporting(E_ALL);
define('DRUPAL_ROOT', getcwd());
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_rebuild();