Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Drupal quick tip of the day: react differently to CLI calls

Parent Feed: 

Sometimes you want to react differently, when the current script is running in a command-line environment. Drupal does this internally e.g. for session handling.

In Drupal 7, there was a dedicated drupal_is_cli() function.

In Drupal 8, this function was removed because you can instead directly check the PHP_SAPI constant:


if (PHP_SAPI === 'cli') {
  // Do stuff
}
Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web