Skip to content

Commit b5478b3

Browse files
authored
Merge pull request #5393 from kenjis/fix-is-cli
fix: `is_cli()` returns `true` when `$_SERVER['HTTP_USER_AGENT']` is missing
2 parents 5dcad2c + 00fc585 commit b5478b3

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

system/Common.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -643,16 +643,13 @@ function helper($filenames)
643643
*/
644644
function is_cli(): bool
645645
{
646-
if (defined('STDIN')) {
646+
if (in_array(PHP_SAPI, ['cli', 'phpdbg'], true)) {
647647
return true;
648648
}
649649

650-
if (! isset($_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']) && isset($_SERVER['argv']) && count($_SERVER['argv']) > 0) {
651-
return true;
652-
}
653-
654-
// if source of request is from CLI, the `$_SERVER` array will not populate this key
655-
return ! isset($_SERVER['REQUEST_METHOD']);
650+
// PHP_SAPI could be 'cgi-fcgi', 'fpm-fcgi'.
651+
// See https://github.com/codeigniter4/CodeIgniter4/pull/5393
652+
return ! isset($_SERVER['REMOTE_ADDR']) && ! isset($_SERVER['REQUEST_METHOD']);
656653
}
657654
}
658655

0 commit comments

Comments
 (0)