Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
  1. Home
  2. Blog
  3. Work That Should Not Happen During a Request
PHP Development

Work That Should Not Happen During a Request

Background jobs and queues in PHP: moving email, reports, API calls and image processing out of the request, retryable jobs and supervised workers.

Updated 2 min readBy SpiderHunts Technologies

Free estimateNo obligation

Get a free estimate

Tell us what you need. A senior engineer reads every enquiry.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →

Quick answer — TL;DR

Anything slow, unreliable or non-urgent belongs in a queue. That includes email, report generation, external API calls and image processing.

The request should be fast

A user submitting a form should not wait while an email is sent, a PDF is generated and three external systems are notified. Each of those can fail, and each makes the request slower.

Sending email during a web request is the most common cause of slow form submissions, and the most common reason a form appears to fail when it actually succeeded.

What belongs in a queue

  • Email and notifications
  • Calls to external APIs
  • Report and document generation
  • Image and file processing
  • Bulk data operations
  • Anything that takes more than a moment

What queues give you

  1. Fast responses, because the work happens afterwards
  2. Retries when something transient fails
  3. Durability — work survives a restart
  4. Rate control for external services with limits
  5. Visibility into what failed and why

Design jobs to be retryable

RequirementWhy
IdempotentA retry must not duplicate the effect
Small payloadPass an identifier, not the whole object
Bounded attemptsFailing jobs must not retry forever
Failure handlingA failed job queue somebody actually checks
LoggedSo a missing outcome can be traced

The failed job queue is the part most commonly built and never monitored. Work fails silently and nobody knows.

Workers need supervision

A queue worker that stops leaves work piling up with no error anywhere. It needs a process supervisor to restart it and monitoring to alert when the queue is growing.

Alerting on queue depth is the single most useful monitor in a queued system.

FAQ

Frequently asked questions

The questions readers ask us after this guide.

Still have a question?

Ask us directly — a senior engineer will get back to you.

Ask about your project

What queue backend should we use?

Redis or a database queue for most business applications. A database queue is adequate at modest volume and simpler to run.

How do we know if jobs are failing?

Alert on queue depth and on failed job count. Both should reach a person, not just a log.

Can scheduled tasks replace queues?

For periodic work, yes. For work triggered by user actions, no — the delay is unpredictable.

What about long-running jobs?

Break them into smaller jobs where possible. A job that runs for an hour is difficult to retry and difficult to monitor.

Keep reading

More on PHP Development

PHP Development

Why PHP Is Still a Sensible Choice

Is PHP still a good choice for business applications? Where modern, typed PHP fits, where another language is better, and the hosting and hiring arguments.

PHP Development

Improving Old Code Without a Rewrite

Modernising a legacy PHP application without a rewrite: move to a supported PHP version, add tests around what matters, then strangle rather than replace.

Start here

Forms that take five seconds to submit?

It is usually email being sent during the request. Moving it to a queue is a small change with an immediate effect.

  1. You tell us what you needTwo minutes on the form, or a message on WhatsApp.
  2. A senior engineer reviews itAnd comes back with questions, a realistic range and an honest view on fit.
  3. Free 30-minute scoping callWe talk through scope, options and a realistic estimate — with no obligation.
Free estimateNo obligation

Talk to someone who builds this

Send a short brief and we will come back with an honest view and a realistic range.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →