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

[3.x]: Console methods called in web #11829

Closed
boboldehampsink opened this issue Aug 25, 2022 · 8 comments
Closed

[3.x]: Console methods called in web #11829

boboldehampsink opened this issue Aug 25, 2022 · 8 comments

Comments

@boboldehampsink
Copy link
Contributor

What happened?

Description

Undefined constant "STDOUT"

See this Sentry log: https://sentry.io/share/issue/e795939f38dd4c4e858becf37dc14158/

Craft CMS version

Craft Pro 3.7.52

PHP version

8.1.9

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@brandonkelly
Copy link
Member

Thanks for reporting that! Just released Craft 3.7.53.1 and 4.2.3 with a fix for that.

@dgrigg
Copy link

dgrigg commented May 9, 2024

Seeing this error in Craft 4.5.14
Console::startProgress (u causes the Undefined constant "STDOUT" error. Only happens on our production server.
The code is running inside a Queued Job. This is to output progress to the CLI, separate from the BaseJob setProgress.

The odd part is that if I run ./craft crm/registrations && ./craft queue/run it runs fine in the terminal, but if I only do ./craft crm/registrations and let the crontab for the QueueManager pick it up I see an error in Craft CP

@brandonkelly
Copy link
Member

@dgrigg Can you search for the error in storage/logs/ and post the stack trace?

@dgrigg
Copy link

dgrigg commented May 14, 2024

It only happens if the Queue runs from the CP panel. Executing ./craft queue/run from the CLI runs fine. I ended up creating a Console Trait that wrapped the functions with this if (defined('STDOUT') and added that to the Jobs to get around the issue. Any of the output functions in yii\helpers\Console throw the error.

queue-2024-05-14.log

@brandonkelly
Copy link
Member

Looks like it’s getting called from a module file:

#2 /var/www/thermacell/modules/crm/jobs/ProductDataJob.php(122): yii\helpers\BaseConsole::startProgress(0, 366, 'PRODUCTS: 366 ')

So you’ll need to adjust that code yourself.

Queue jobs should not assume that they will be run from a CLI request.

@dgrigg
Copy link

dgrigg commented May 14, 2024

Yes, I fixed the code. The issue is that it's throwing that error in the first place. I guess the Queue process does not define STDOUT anywhere?

@brandonkelly
Copy link
Member

Your code is calling a method on the Console helper, which should only ever be invoked on a CLI request. It’s expected that errors will occur if you do that from a web request. Nothing in the queue or built-in queue jobs is built to assume that it will be run from a CLI request.

@dgrigg
Copy link

dgrigg commented May 14, 2024

Got it. Makes sense. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants