1.   echo var_dump(drupal_is_cli(), PHP_SAPI, PHP_SAPI === 'cli'), "\n";
    
  2. $ ./core/scripts/run-tests.sh
    ---
    bool(false)
    string(3) "cli"
    bool(true)
    

This is somewhat caused by run-tests.sh itself, which performs:

simpletest_script_init("Apache");
...
function simpletest_script_init($server_software) {
  $_SERVER['SERVER_SOFTWARE'] = $server_software;
}

(which I do not understand)

However, we absolutely need to be able to identify and differentiate a CLI process from a web request process in the (http) kernel architecture.

CommentFileSizeAuthor
#1 drupal8.cli_.1.patch527 bytessun
drupal8.cli_.0.patch585 bytessun
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Issue tags: -symfony
FileSize
527 bytes

The last submitted patch, drupal8.cli_.0.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 1: drupal8.cli_.1.patch, failed testing.

sun’s picture

Adding parent issue.

The reason is that we do not want to start a session on PHP CLI. — Currently, we do, because of this slightly weird check in drupal_is_cli().

sun’s picture

Status: Needs work » Needs review
Damien Tournoud’s picture

Title: drupal_is_cli() returns TRUE on PHP CLI » drupal_is_cli() returns FALSE on PHP CLI
ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

i guess we can mark it deprecated as well, but probably in another issue

webchick’s picture

Status: Reviewed & tested by the community » Fixed

I git blamed on this line and found #581286: Detect CLI environments properly which is very non-descriptive as to what we were actually trying to fix, but it links to #487300: Drush hangs when using Pressflow for more background. About halfway down Pressflow is identified as the cause, but unfortunately the links to the related Pressflow issues/commits are all 404s now. :\

I asked Moshe if he had any recollection of why we did those gymnastics back in the day. He did not, and recommend we go ahead with this.

On IRC, neclimdul pointed out the code is actually working as designed, and he's correct. run-tests.sh is clearly trying to fake out PHP to pretend it's not actually a CLI script, though to what purpose I couldn't say. We followed git blame all the way to its inception, and these lines were in the initial commit. sun theorizes that it's because of dark magick that had to be done in order to not get the fake Drupal confused with the real Drupal, but since we no longer do that, that theoretically makes this code doubly irrelevant.

Therefore!

Committed and pushed to 8.x. Thanks!

Damien Tournoud’s picture

For the record, we were doing this to sort-of support PHP-CGI used as a poor man PHP-CLI.

People are stuck with this on some crappy hosts, see #1064690: Receiving MANY "Use of undefined constant STDERR" type errors running core-cron for example.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ParisLiakos’s picture