Laravel Queues in Action is now available!

The problem behind Undefined constant 'STDIN' when running Laravel artisan command programmatically

Updated: Nov 13, 2020 — 1 min Read#quick-dip

Undefined constant 'STDIN'

You will see this error if you try to run some artisan commands programmatically from within an HTTP request:

Route::get('/queue-clear', function () {

This is because Laravel will try to prompt for confirmation if the application is running in the production environment. While doing so, the Symfony/Console component will use the built-in STDIN PHP constant to capture the input stream. That constant is only available in the CLI environment.

To avoid this error, you need to use the --force option to disable the interactivity:

Route::get('/queue-clear', function () {
    Artisan::call('queue:clear', [
       '--force' => true

Hey! 👋 If you want to receive updates on what I'm up to, I host a newsletter on my website and would love to have you.

You can also follow me on Twitter, I regularly post about all things Laravel including my latest video tutorials and blog posts.

By Mohamed Said

Hello! I'm a full-stack web developer working at Laravel. In this publication, I share everything I know about Laravel's core, packages, and tools.

You can find me on Twitter and Github.

This site was built using Wink. Follow the RSS Feed.