From 53df2466ab5cfe786892a2036e155b3fc82d25dc Mon Sep 17 00:00:00 2001 From: Zacharias Creutznacher Date: Wed, 6 Aug 2025 09:54:32 +0200 Subject: [PATCH 1/2] Update helpers.md If you have the swoole PHP extension installed, Laravel's defer() helper may conflict with the global defer() provided by Swoole. Would be great to have this warning in the docs. --- helpers.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/helpers.md b/helpers.md index a02e880bac..17c7be9f62 100644 --- a/helpers.md +++ b/helpers.md @@ -3199,6 +3199,9 @@ For a thorough discussion of Carbon and its features, please consult the [offici ### Deferred Functions +> [!WARNING] +> If you have the **swoole** PHP extension installed, Laravel's `defer()` helper may conflict with Swoole's global defer() function, leading to a `502 Bad Gateway` error from Nginx. Make sure you call the defer helper by explicitly namespacing it: `use function Illuminate\Support\defer;` + While Laravel's [queued jobs](/docs/{{version}}/queues) allow you to queue tasks for background processing, sometimes you may have simple tasks you would like to defer without configuring or maintaining a long-running queue worker. Deferred functions allow you to defer the execution of a closure until after the HTTP response has been sent to the user, keeping your application feeling fast and responsive. To defer the execution of a closure, simply pass the closure to the `Illuminate\Support\defer` function: From 7c476136e4df25081e2a2a109bb41b3db5f0d463 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 6 Aug 2025 10:08:49 -0500 Subject: [PATCH 2/2] Update helpers.md --- helpers.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/helpers.md b/helpers.md index 17c7be9f62..55991be602 100644 --- a/helpers.md +++ b/helpers.md @@ -3199,9 +3199,6 @@ For a thorough discussion of Carbon and its features, please consult the [offici ### Deferred Functions -> [!WARNING] -> If you have the **swoole** PHP extension installed, Laravel's `defer()` helper may conflict with Swoole's global defer() function, leading to a `502 Bad Gateway` error from Nginx. Make sure you call the defer helper by explicitly namespacing it: `use function Illuminate\Support\defer;` - While Laravel's [queued jobs](/docs/{{version}}/queues) allow you to queue tasks for background processing, sometimes you may have simple tasks you would like to defer without configuring or maintaining a long-running queue worker. Deferred functions allow you to defer the execution of a closure until after the HTTP response has been sent to the user, keeping your application feeling fast and responsive. To defer the execution of a closure, simply pass the closure to the `Illuminate\Support\defer` function: @@ -3227,6 +3224,9 @@ By default, deferred functions will only be executed if the HTTP response, Artis defer(fn () => Metrics::reportOrder($order))->always(); ``` +> [!WARNING] +> If you have the **swoole** PHP extension installed, Laravel's `defer` function may conflict with Swoole's own global `defer` function, leading to web server errors. Make sure you call Laravel's `defer` helper by explicitly namespacing it: `use function Illuminate\Support\defer;` + #### Cancelling Deferred Functions