Checking if You're Running in the Console


You want to check if your application is running in the console.

You know you can check php_sapi_name() but would like to use the more elegant, Laravel way.


Use App::runningInConsole()

if (App::runningInConsole())
    echo "I'm in the console, baby!";


Laravel actually uses php_sapi_name() to implement this method.

If php_sapi_name() equals 'cli' then your code is running in the console.

comments powered by Disqus