Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

3. Customizing Drush > Executing custom PHP scripts

Executing custom PHP scripts

Sometimes you may only need to run a few PHP commands after bootstrapping Drupal. For example, to view the value of a server variable, to programmatically submit a form, and to print the output of a very complex database query that needs some placeholders. Normally, to achieve this, you would copy index.php to a temporary file, remove the line that invokes the controller and type in your own code. Drush helps you do this more easily and securely through the commands php-eval and php-script.

Executing PHP code from the command line

php-eval accepts some PHP code between quotes and executes it. If it can bootstrap a Drupal site, it will do it first, allowing us to interact with it. Here are a couple of examples:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint