PHP Community · The edge cases the PHP docs never spell out

596
phpr/php·posted by linlin·3 days agoDiscussion

The edge cases the PHP docs never spell out

Most PHP articles stop at "how to use it" and never cover "when not to use it". This is an attempt at the second half.

Worth noting: the official docs do cover this, just in a very inconspicuous spot. I only found it reading the source comments, where the author explains the reasoning — roughly "so that it degrades into predictable behaviour in extreme cases".

Documentation first44%
Source code first28%
Just ask someone17%
Run a demo and learn by error11%

1013 votes total

345 comments

345 comments

· first 120 loaded
M
Mmike_xu·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

518
Zzhu_zong·2 days ago

This is not a PHP problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

414
Kkernel_panic·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

158
Lli_ming·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

412
Mmike_xuOP·1 hour ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

282
Mmike_xu·2 days agoedited

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.

87
Hhuang_ke·2 days ago

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.

226
Zzhou_yi·just now

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

332
Rran_bo·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

390
Hhuang_ke·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

20
Ddev_zhouMod·5 hours ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

300
Bbob_chen·3 minutes ago

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.

247
Nnikic·2 days ago

I just read the PHP source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

256
Wwinter·2 days agoedited

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

212
Zzhu_zong·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

99
Sslow_query·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

11
Hhuang_ke·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

1
Kkernel_panic·2 days ago

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.

174
Lli_ming·2 days ago

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.

136
Rrase·5 hours agoedited

I just read the PHP source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

35
Hhuang_keOP·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

253
Kkernel_panic·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

435
Rrase·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

216
Mmike_xu·2 days ago

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.

299
Llinlin·2 days 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.

284
Oops_wang·2 days ago

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.

479
Oops_wang·12 minutes ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

241
Ddev_zhou·3 minutes ago

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.

15
Zzhou_yi·2 hours ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

149
Mmike_xuOP·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

431
Lli_ming·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

432
Kkite·2 days agoedited

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

155
Zzhu_zongOP·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

519
Zzhou_yiMod·2 days agoLevel 6

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

2
Sswoole_lee·2 days ago

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.

206
Wwinter·2 days agoLevel 6

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

338
Bbob_chen·12 minutes agoLevel 6

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

17
Mmike_xu·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

1
Rrase·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

32
Hhuang_ke·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

52
Kkernel_panic·2 days agoedited

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

238
Rrase·2 hours ago

I just read the PHP source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

30
Sswoole_lee·12 minutes ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

503
Oops_wang·2 days ago

This is not a PHP problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

244
Llinlin·2 hours ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

13
Kkernel_panicOP·2 days agoLevel 6

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

492
Zzhu_zong·2 days agoLevel 6

Saved. I am reworking this area this week — this saves a lot of wrong turns.

437
Mmike_xuMod·2 days agoLevel 6

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

18
Mmike_xu·12 minutes ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

199
Wwinter·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

477
Lli_ming·2 days agoLevel 6

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

168
Sswoole_lee·2 days agoLevel 6

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

4
Hhuang_ke·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.

226
Mmike_xu·2 days agoLevel 6

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.

23
Zzhu_zong·3 minutes ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

20
Sslow_query·yesterday

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

6
Ddev_zhou·12 minutes agoLevel 6

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

132
Kkite·2 days agoeditedLevel 6

This is not a PHP problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

100
Zzhu_zong·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

188
Mmike_xu·28 minutes ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

2
Kkernel_panic·12 minutes agoedited

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

239
Rrase·5 hours ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

229
Cchen_devOP·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

145
Kkite·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

203
Zzhu_zong·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

164
Wwinter·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

158
Bbob_chen·just now

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

143
Kkernel_panic·2 days ago

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.

130
Rran_bo·2 hours 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.

108
Rran_bo·2 days ago

This is not a PHP problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

6
Sslow_query·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

103
NnikicOP·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

27
Cchen_dev·2 days ago

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.

85
NnikicOP·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

462
Ddev_zhouOP·2 days ago

Has anyone run a controlled experiment? I did, reducing it to a single variable, and the difference was 4% — within noise. So I suspect the main cause is something else.

14
Kkernel_panic·2 days ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

71
Ttang_hao·28 minutes ago

This is not a PHP problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

70
Ddev_zhouMod·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

70
Rrase·2 hours ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

19
Kkernel_panicOP·2 days ago

I just read the PHP source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

477
Lli_ming·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

215
Rrase·3 minutes ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

69
Rran_bo·5 hours 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.

65
Bbob_chen·2 days ago

I just read the PHP source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

117
Aalice_devOP·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

2
Lli_mingOP·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

1
Ttang_hao·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

52
Oops_wang·3 minutes ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

49
Sslow_query·28 minutes ago

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.

44
Wwinter·2 days ago

I just read the PHP source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

43
Aalice_dev·2 days ago

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.

228
Mmike_xu·2 days 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.

289
Ttang_hao·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

268
Hhuang_keMod·12 minutes ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

36
Lli_ming·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

242
Zzhou_yi·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

448
Ttang_haoOP·2 days ago

Agreeing with the above. One addition: with this option enabled the GC count in your metrics doubles, so adjust the alert threshold at the same time or it will keep firing.

1
KkiteMod·2 hours ago

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.

16
NnikicMod·2 days 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.

218
Zzhu_zong·2 days ago

Thanks for sharing real numbers — far more useful than the articles that only cover concepts.

36
Nnikic·2 days ago

I see point 3 differently. The trade-off depends on your read/write ratio: read-heavy with little writing means caching actually widens the inconsistency window.

36
Oops_wang·2 days 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.

17
Rrase·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

85
Kkernel_panic·2 days ago

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

2
Mmike_xu·2 hours ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

5
Ttang_hao·2 hours ago

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

16
Oops_wang·2 days ago

This is not a PHP problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

8
Rrase·2 days ago

This is not a PHP problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

16
Wwinter·2 days ago

Sharing our numbers, 8 cores 16GB, same scenario:

| Concurrency | P50 | P99 |
|---|---|---|
| 200 | 12ms | 88ms |
| 500 | 31ms | 340ms |

P99 clearly collapses at 500 concurrency, which lines up with your knee point.

10
Sswoole_lee·2 days 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.

1
Zzhou_yi·2 days ago

This is not a PHP problem, it is a usage problem. The docs say this API is not thread-safe and you must lock around it yourself.

137
Oops_wang·2 days ago

I just read the PHP source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

9
Kkite·12 minutes ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

281
Oops_wang·2 days ago

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

8
Ttang_hao·2 days ago

I just read the PHP source — the author actually explains the reasoning in a comment, roughly "so that it degrades into predictable behaviour in extreme cases".

3
Hhuang_ke·2 days agoedited

A question: what changes in a container with a 512Mi memory limit? That is how we run it in production.

3
Mmike_xu·2 days agoedited

Worth learning from this debugging approach. We went straight at the logs and took a much longer route.

2
Wwinter·2 days ago

Saved. I am reworking this area this week — this saves a lot of wrong turns.

1
Hhuang_ke·yesterdayedited

Can you give a minimal reproduction? I ran it locally for ten minutes and could not reproduce on macOS with the latest version.

376
Cchen_dev·2 days ago

This matches what we see in production. We only hit it past 3k QPS; the earlier load tests showed nothing — the test traffic was too clean, with no long-tail requests.

1

This is the post detail page /en/c/php/post/p11. 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 →