Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Speed up runningInConsole method #30922

Merged
merged 3 commits into from Dec 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Illuminate/Foundation/Application.php
Expand Up @@ -131,6 +131,13 @@ class Application extends Container implements ApplicationContract, HttpKernelIn
*/
protected $environmentFile = '.env';

/**
* Indicates if the application is running in the console.
*
* @var bool|null
*/
protected $isRunningInConsole;

/**
* The application namespace.
*
Expand Down Expand Up @@ -551,11 +558,11 @@ public function detectEnvironment(Closure $callback)
*/
public function runningInConsole()
{
if (Env::get('APP_RUNNING_IN_CONSOLE') !== null) {
return Env::get('APP_RUNNING_IN_CONSOLE') === true;
if ($this->isRunningInConsole === null) {
$this->isRunningInConsole = Env::get('APP_RUNNING_IN_CONSOLE') ?? (\PHP_SAPI === 'cli' || \PHP_SAPI === 'phpdbg');
}

return php_sapi_name() === 'cli' || php_sapi_name() === 'phpdbg';
return $this->isRunningInConsole;
}

/**
Expand Down