DEV Community

Cover image for PHP Dies After Every Request. How the Zend Engine Actually Runs Your Code.

PHP Dies After Every Request. How the Zend Engine Actually Runs Your Code.

S M Tahosin on November 09, 2026

For more than two decades, programmers coming from languages like Java, Python, Go, and Node.js have looked at PHP and repeated the exact same crit...
Collapse
 
ggle_in profile image
Jack •

The part I think gets skipped in most comparisons is that shared-nothing bounds the blast radius at the worker, not just at the request. A segfault in one FPM worker doesn’t take down the pool, and that’s a real architectural advantage over long-lived runtimes that’s hard to retrofit later. The other correction worth repeating is that “PHP re-parses every request” has been false for over a decade; the OPcache and preloading section makes that concrete instead of hand-wavy, and I wish more intros to PHP runtime internals led with it.

Happy to compare notes on this, and glad to connect with others working on PHP runtime internals or production tuning.

What I can’t get past is that the teardown frees memory, not server-side session state. PDO::ATTR_PERSISTENT hands the same MySQL connection to the next request served by that worker, so SET @leak, time_zone, an open transaction, or LAST_INSERT_ID() can survive the reset, and pm.max_requests defaults to 0, so a worker can hold that connection for its whole life. APCu and static vars in preloaded classes also outlive the request. So “every byte reclaimed” is true for the request heap, not for everything the worker is holding.

A realistic addition would be a short “what actually persists across requests” section or diagram — OPcache SHM, preloaded statics, APCu, persistent PDO connections, realpath cache, worker lifetime — plus the two-line audit: log getmypid() next to the connection id, and check pm.max_requests. That would make the shared-nothing claim precise without weakening it.

Collapse
 
smtahosin profile image
S M Tahosin •

Really good points. The worker-level blast radius is underrated, and you're right that OPcache killed the "re-parses every request" myth long ago. Persistent PDO, APCu, and preloaded statics surviving is a fair correction. Logging getmypid() next to the connection id is a smart quick audit. Might add a short "what actually persists" note. Thanks for the detailed feedback!

Collapse
 
mohsen_jr profile image
Mohsen jr •

Not on their own. Someone can visit a pricing page out of curiosity, while another person might be ready to buy after reading just one page. Clicks show interest, but actions like requesting a quote, checking availability, or contacting sales reveal much stronger buying intent.

Collapse
 
smtahosin profile image
S M Tahosin •

Hey, not sure this connects to the post. Maybe it landed on the wrong article? Happy to chat about PHP if you have thoughts on the runtime side.

Collapse
 
alexshev profile image
Alex Shev •

Explaining the request lifecycle makes several PHP design choices easier to reason about, especially where state actually persists and where it only appears to. A companion diagram of opcode cache, worker lifetime, and external session or queue state would help readers avoid the common mistake of treating a process-local optimization as durable application state.

Collapse
 
smtahosin profile image
S M Tahosin •

Agreed, a simple diagram of what lives in the worker vs what dies with the request would make the boundary clearer. Good suggestion. Thanks!

Collapse
 
onelifevibe profile image
OneLifeVibe •

The framing of dying on purpose as a superpower is what makes this click. I had always treated PHP's per-request teardown as a limitation to work around, not as the thing that bounds the blast radius when a worker crashes or a leak creeps in. The OPcache section was the most useful correction for me: the idea that PHP re-parses everything on every request died a decade ago, and preloading makes that even clearer. The 16-byte zval and copy-on-write details tie it together nicely, the runtime can afford to throw everything away because so much of the work is already cheap or shared. Great deep dive.

Collapse
 
smtahosin profile image
S M Tahosin •

Glad the framing clicked. Treating the teardown as a feature instead of a bug changes how you see the whole design. Happy the OPcache and zval bits helped too. Appreciate you reading it closely!

Collapse
 
dafili profile image
Renhua Wei •

Shared-nothing stops at the process boundary, not at the socket: PDO::ATTR_PERSISTENT hands the same MySQL connection to the next request served by that FPM worker, so session-scoped state outlives the reset -- request A runs SET @leak=42 and request B's SELECT @leak answers 42, same as SET time_zone, a transaction left open by a fatal, and LAST_INSERT_ID(). Two lines settle whether you are exposed: log getmypid() next to your connection thread id on every request and look for a repeat, and read pm.max_requests -- the default is 0, so a worker can hold that connection for its whole life. The teardown frees memory, not the server-side session.

Collapse
 
smtahosin profile image
S M Tahosin •

Sharp catch. Persistent connections and server-side session state do outlive the request heap. The getmypid() + connection id check is a clean way to spot it. Thanks for spelling it out so clearly.

Collapse
 
fm profile image
Fayaz •

OK, so the haters are correct then!
They just don't understand the true semantics.
PHP is not dead, it dies again and again 🤣🥰

Collapse
 
smtahosin profile image
S M Tahosin •

Haha exactly. It dies on purpose, and that's the whole point. 🤣