Add opt-in output forwarding for scheduled foreground commands#60729
Open
ManicardiFrancesco wants to merge 1 commit into
Open
Add opt-in output forwarding for scheduled foreground commands#60729ManicardiFrancesco wants to merge 1 commit into
ManicardiFrancesco wants to merge 1 commit into
Conversation
Generalizes the existing Laravel Cloud-only stdout/stderr forwarding into an explicit opt-in API so self-hosted/containerized deployments can pick up scheduled command output via `docker logs`/`kubectl logs` without application-level workarounds (temp files + after() callbacks). - Event::forwardOutputToConsole() opts a single event in. - Schedule::forwardOutputToConsole() opts every foreground event in, regardless of call order (mirrors Schedule::$pausable/$interruptible and useCache()). - Output is streamed to the configured destination via the Process callback instead of shell redirection, so exit codes are preserved, memory stays bounded for chatty commands, and it works on Windows (no `tee` dependency). - Background events are intentionally unaffected: they already run through a detached shell that owns its own output redirection. - Defaults are unchanged; Laravel Cloud behavior is untouched.
shaedrich
reviewed
Jul 10, 2026
| /** | ||
| * Get the callback used to forward the process output to the console. | ||
| * | ||
| * @return callable |
Contributor
There was a problem hiding this comment.
You could narrow this down:
Suggested change
| * @return callable | |
| * @return callable(object|string, string): true|null |
or even
Suggested change
| * @return callable | |
| * @return callable(object|string, 'err'|'out'): true|null |
| /** | ||
| * Write a line of process output to the console's standard streams. | ||
| * | ||
| * @param string $type |
Contributor
There was a problem hiding this comment.
You might be able to narrow this further:
Suggested change
| * @param string $type | |
| * @param 'err'|'out' $type |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Laravel currently forwards scheduled command output (stdout/stderr) to the parent
schedule:runprocess only when running on Laravel Cloud (#53623). On self-hosted/containerized deployments (Docker, Kubernetes), scheduled command output is redirected to a file or/dev/nullby default, so log lines written by scheduled commands (e.g.LOG_CHANNEL=stderr) never reachdocker logs/kubectl logs, even though the parent "Running [...]" line does. Discussion #47448 tracks demand for this; a previous attempt (#56611) added default forwarding and was closed because the implementation wasn't loved.This PR generalizes the existing Laravel Cloud capability into an explicit, opt-in API instead of changing default behavior:
Event::forwardOutputToConsole()opts a single event in.Schedule::forwardOutputToConsole()is a schedule-wide static toggle (mirrorsSchedule::$pausable/$interruptible/useCache()) — it applies to every foreground event regardless of whether it's called before or aftercommand()/exec().sendOutputTo/appendOutputTo) via the SymfonyProcessoutput callback instead of shell redirection (tee), so:tee),teedependency.runInBackground()) are intentionally unaffected — they already run through a detached shell that owns its own output redirection viaschedule:finish, so there is nothing for this process to forward. Covered explicitly by tests rather than attempting to support it.ScheduledTaskFailed+ reported) instead of silently succeeding.laravel_cloud()) is untouched.This avoids application-level workarounds like writing to a temp file and using
after()tofwriteit out.Test plan
Event::forwardOutputToConsole()sets the flag and returns$thisteewhen forwarding is enabled (including a failing command, to verify exit code preservation)Event::execute()uses the forwarding callback when enabled, and the no-op callback by defaultsendOutputTo/appendOutputTo), both truncating and appendingSchedule::forwardOutputToConsole()applies to events created before and after the call (integration test through realschedule:runexecution)teepath) is unchangedtests/Consoleandtests/Integration/Consolesuites pass; Pint and PHPStan clean on touched files🤖 Generated with Claude Code