Skip to content
OpenCloseEsc
Tips
  • Laravel
  • queue
  • performance

Run small work after the response without a queue worker

dispatchAfterResponse() sends the HTTP response first and runs the job in the same process afterwards, which is enough for an email or a log line.

1 min read

Not every project has a queue worker running, and not every task deserves one. For something that takes under a second, let the request finish first.

SendReceipt::dispatchAfterResponse($order);

The response is flushed to the browser, then the job's handle() runs in the same PHP process, so the visitor does not wait for the mail server. The same works for closures: dispatch(fn () => Log::info('done'))->afterResponse().

It is not a queue: there are no retries and nothing survives a crash. Once the work takes seconds or must not be lost, move it to a real queue.