PHP Community · This PHP bug hid for three years before anyone reported it

12
phpr/php·posted by kernel_panic·2 hours agoDiscussion

This PHP bug hid for three years before anyone reported it

It took me two weeks of on-and-off digging and plenty of wrong turns. Writing the process down as it happened so the next person spends less time.

What genuinely surprised me was the tail. The average looked great while P99 jumped by an order of magnitude past some threshold. The cause was not PHP itself but our upstream connection reuse — the load test traffic was too clean and hid the long-tail requests.

On trade-offs, my view is this: if nobody on the team owns this area long-term, do not introduce a second mechanism. With two coexistence you first have to work out which one is even in play when things break, and that costs far more than the performance you saved.

Ssegmentfault.comExternal link · opens in a new tab
3 comments

3 comments

M
Wwinter·just nowedited

One counter-example: below PHP 7.4 the semantics of that code are different, so do not copy it verbatim. We got burned in staging and rolled back once.

67
Bbob_chen·3 minutes ago

We have run this in production for two years without hitting it. That said, we never reached this scale, so our experience is not really evidence here.

35
Aalice_dev·just now

There is actually a simpler fix that needs no architecture change: move this check up to the gateway and the problem disappears. The cost is one extra lookup at the gateway.

9

This is the post detail page /en/c/php/post/p8. Posts and comments are generated deterministically from a seeded PRNG, so the same post always renders the same content and the link can be shared, reloaded and indexed. In production this page reads MySQL for the post, Redis for hot-post caching, and fetches the whole comment tree in a single query on the path column.

See the database schema →