PHP Community · The PHP execution flow in one diagram (with sequence chart)

1.7K
phpr/php·posted by tang_hao·3 days agoAnnouncement

The PHP execution flow in one diagram (with sequence chart)

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".

Performance44%
Maintainability28%
Ecosystem and community17%
Hiring difficulty11%

2900 votes total

464 comments

464 comments

· first 120 loaded
M
Bbob_chen·12 minutes 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.

514
Sslow_query·2 hours ago

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

492
Ttang_hao·28 minutes 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.

445
Kkernel_panic·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.

1
Zzhou_yi·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.

432
Kkite·2 days agoedited

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

415
Cchen_dev·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".

1
Cchen_dev·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.

408
Llinlin·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.

332
Sslow_query·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.

24
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".

159
Lli_ming·2 days ago

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

3
Zzhou_yi·1 hour ago

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

1
Sslow_query·2 days ago

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

308
Lli_ming·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.

295
Kkernel_panic·2 days ago

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

30
Bbob_chen·3 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.

252
Nnikic·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.

27
Zzhu_zong·2 days agoedited

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

231
Ddev_zhou·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.

229
Cchen_dev·2 days agoedited

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

228
Oops_wang·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.

222
Zzhu_zong·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.

180
Ttang_haoOP·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.

404
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.

310
Cchen_dev·2 days ago

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

119
Bbob_chenOP·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".

246
Sslow_query·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.

34
Zzhu_zong·2 days ago

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

1
Ddev_zhou·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.

515
Zzhou_yi·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.

154
Llinlin·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.

101
Kkernel_panic·yesterday

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

87
Mmike_xuOP·2 days agoedited

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

9
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.

13
Ddev_zhou·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.

11
Ttang_hao·just now

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

67
Aalice_dev·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".

65
Mmike_xuOP·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.

3
Nnikic·12 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.

50
Kkernel_panic·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.

378
Llinlin·2 days ago

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

1
Ddev_zhou·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.

372
Kkernel_panic·just now

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

333
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.

3
Cchen_devOP·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.

78
Nnikic·5 hours 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.

139
Wwinter·12 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.

257
Hhuang_ke·5 hours agoedited

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.

90
Oops_wang·2 days agoLevel 6

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.

164
Rran_boOP·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.

9
Ddev_zhou·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.

12
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.

8
Zzhou_yi·2 days ago

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

20
Bbob_chen·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.

48
Sswoole_lee·12 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.

1
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.

389
Aalice_dev·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.

209
Zzhou_yiOP·2 days agoLevel 6

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

96
Rran_bo·2 days agoLevel 6

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.

144
Lli_ming·2 days ago

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

1
Sslow_queryOP·3 minutes agoedited

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.

253
Rrase·2 days agoeditedLevel 6

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

124
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.

83
Zzhu_zong·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.

49
Llinlin·1 hour ago

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

44
Sslow_queryOPMod·2 days ago

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

57
Bbob_chen·just now

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

1
Zzhou_yi·2 days ago

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

243
Kkite·2 days ago

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

1
Lli_ming·2 days 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.

163
Oops_wang·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.

213
Sslow_query·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.

40
LlinlinOP·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.

44
WwinterMod·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.

78
Mmike_xu·yesterday

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

356
Cchen_dev·5 hours agoLevel 6

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.

36
Kkernel_panic·2 days agoLevel 6

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

28
Bbob_chen·2 days agoLevel 6

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.

4
Aalice_dev·2 days agoLevel 6

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
Aalice_dev·2 days agoLevel 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.

1
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.

310
Ttang_hao·5 hours agoeditedLevel 6

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

69
WwinterOP·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.

200
Rrase·2 days agoLevel 6

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

173
KkiteOP·2 days agoLevel 6

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.

4
Bbob_chen·2 days agoLevel 6

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

50
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.

21
Llinlin·2 days agoLevel 6

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".

121
Kkite·2 days agoLevel 6

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.

28
Aalice_dev·3 minutes 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.

63
Wwinter·yesterday

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.

1
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".

1
Ddev_zhou·2 days agoLevel 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.

199
Mmike_xu·1 hour 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.

40
Aalice_dev·2 days ago

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

35
Mmike_xu·yesterday

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.

33
Nnikic·2 days ago

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

413
Cchen_dev·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.

31
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.

28
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.

1
Rrase·2 days ago

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

24
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.

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

368
Sslow_query·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.

227
Oops_wang·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.

202
Zzhou_yi·2 days ago

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

6
Kkite·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.

35
Cchen_dev·yesterday

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

335
LlinlinOP·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.

343
Nnikic·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.

280
Kkernel_panicMod·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.

76
Wwinter·12 minutes 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.

9
Sswoole_lee·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.

9
Wwinter·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.

6
Nnikic·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.

1
Sswoole_lee·yesterday

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

4
Zzhu_zong·1 hour 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
Zzhou_yi·1 hour 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
Ddev_zhou·2 days 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".

1

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