Skip to content

php:script

Run php a script after a full Drupal bootstrap.

A useful alternative to eval command when your php is lengthy or you can't be bothered to figure out bash quoting. If you plan to share a script with others, consider making a full Drush command instead, since that's more self-documenting. Drush provides commandline options to the script via a variable called $extra.

Examples

  • drush php:script example --script-path=/path/to/scripts:/another/path. Run a script named example.php from specified paths
  • drush php:script -. Run PHP code from standard input.
  • drush php:script. List all available scripts.
  • drush php:script foo -- apple --cider. Run foo.php script with argument apple and option cider. Note the -- separator.

Arguments

  • [extra]....

Options

  • --format[=FORMAT]. [default: var_export]
  • --script-path=SCRIPT-PATH. Additional paths to search for scripts, separated by : (Unix-based systems) or ; (Windows).

Global Options

  • -v|vv|vvv, --verbose. Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
  • -y, --yes. Auto-accept the default for all user prompts. Equivalent to --no-interaction.
  • -l, --uri=URI. A base URL for building links and selecting a multi-site. Defaults to https://default.
  • To see all global options, run drush topic and pick the first choice.

Topics

Aliases

  • scr
  • php-script

Legend

  • An argument or option with square brackets is optional.
  • Any default value is listed at end of arg/option description.
  • An ellipsis indicates that an argument accepts multiple values separated by a space.