Sometimes, you need to test a piece of code after Drupal has bootstrapped, but you do not know how. I remember, when I started using Drupal, that I would copy index.php
in test.php
, replace the last line with whatever code I wanted to test, and then open this file in the web browser to see its result. This was an easy approach, but I felt it was wrong because I was hijacking Drupal's router: index.php
.
Drush has two commands to let you run code after Drupal has been bootstrapped. This accomplishes the same goal as the approach mentioned in the preceding code (copying and hijacking index.php
), but in a cleaner way. These commands are:
php-eval
: This lets you run PHP code in the command-line interface. It is useful when you want to test a few statements. This is like using the PHP's interactive shell (http://php.net/manual/en/features.commandline.interactive.php), but in a Drupal context.php-script
: This executes a given script file after Drupal...