# PHP True Async RFC Stage 5

- Thread: https://externals.io/message/129004
- Original archive: https://news-web.php.net/php.internals/129004
- Started by Edmond Dantes on 2025-10-30T08:19:40+00:00
- Messages: 71
- Page 1 of 3: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/129004.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #129004 — Edmond Dantes — 2025-10-30T08:19:40+00:00

URL: https://externals.io/message/129004#129004

Hi

1.5 RFC:
https://wiki.php.net/rfc/true_async

Here’s the fifth version of the RFC with the updates made after the
1.4 discussion.

Starting from 2025-11-03, there will be a two-week discussion period.

**Changelog:**

* Added FutureLike interface methods: cancel(), isCompleted(), isCancelled()
* Renamed Coroutine::isFinished() to Coroutine::isCompleted()
* Clarified exit/die behavior: always triggers Graceful Shutdown mode
regardless of where called
* Added rationale for “Cancellable by design” policy: explains why
default cancellability reduces code complexity for read-heavy PHP
workloads
* RFC structure improvements: reorganized Cancellation section with
proper subsections hierarchy
* Moved “Coroutine lifetime” as subsection under Coroutine section
* Extended glossary with Awaitable, Suspension, Graceful Shutdown, and
Deadlock terms
* Introduced FutureLike interface with single-assignment semantics and
changed await() signature to accept FutureLike instead of Awaitable
for type safety
* Split RFC: Moved Scope and structured concurrency functionality to
separate Scope RFC. Base RFC now focuses on core async primitives
(coroutines, await, cancellation)

I decided not to wait until Monday and made the changes today. If
anyone has read version 1.4 and has comments on it, they’re still
relevant.

The Scope API has been moved to a separate RFC:
https://wiki.php.net/rfc/true_async_scope

----
Best Regards, Ed

---

## #129006 — Deleu — 2025-10-30T13:32:43+00:00

URL: https://externals.io/message/129004#129006 · In reply to: #129004

Hi Edmond!



> Hi
>
> 1.5 RFC:
> https://wiki.php.net/rfc/true_async
>
> Here’s the fifth version of the RFC with the updates made after the
> 1.4 discussion.
>
> Starting from 2025-11-03, there will be a two-week discussion period.
>
> **Changelog:**
>
> * Added FutureLike interface methods: cancel(), isCompleted(),
> isCancelled()
> * Renamed Coroutine::isFinished() to Coroutine::isCompleted()
> * Clarified exit/die behavior: always triggers Graceful Shutdown mode
> regardless of where called
> * Added rationale for “Cancellable by design” policy: explains why
> default cancellability reduces code complexity for read-heavy PHP
> workloads
> * RFC structure improvements: reorganized Cancellation section with
> proper subsections hierarchy
> * Moved “Coroutine lifetime” as subsection under Coroutine section
> * Extended glossary with Awaitable, Suspension, Graceful Shutdown, and
> Deadlock terms
> * Introduced FutureLike interface with single-assignment semantics and
> changed await() signature to accept FutureLike instead of Awaitable
> for type safety
> * Split RFC: Moved Scope and structured concurrency functionality to
> separate Scope RFC. Base RFC now focuses on core async primitives
> (coroutines, await, cancellation)
>
> I decided not to wait until Monday and made the changes today. If
> anyone has read version 1.4 and has comments on it, they’re still
> relevant.
>
> The Scope API has been moved to a separate RFC:
> https://wiki.php.net/rfc/true_async_scope
>
> ----
> Best Regards, Ed
>

Thanks for the RFC update! I've been trying to read and understand this RFC
since its earlier versions and I can definitely feel it getting easier to
digest, which I can only assume it's a good thing for RFC voters - it's
easier to vote No because something is too complex / too hard to understand.

One minor question: is this section
https://wiki.php.net/rfc/true_async#awaiting_a_result_with_cancellation
named wrongly? I'm not sure how this snippet of code relates to
cancellation.

Onto more important things. In regards to the change of Awaitable vs
FutureLike, my understanding of the discussion is that on the
implementation side it was asked about whether an Awaitable object should
be awaited in a loop (consumed until completion) or if it should be awaited
only once, which also raised the question about idempotency and whether an
object is awaitable more than once. While the change makes the type-system
somewhat more explicit in regards to how await() is meant for a single-shot
Awaitable object (named FutureLike), it does mean the implementation of
things like awaitAll(Awaitable[] $awaitables) is no longer a simple loop to
await every item in the array.

My questions are:
- What's the difference between Multishot Awaitables and Generators?
- If await() is hardened to FutureLike only, doesn't this mean that
multishot awaitables are not really capable of being awaited anymore?
Doesn't this mean that the Awaitable interface becomes out-of-sync with the
await() function and it stops making sense?
- Shouldn't FutureLike be Awaitable and what has been described as
Multishot awaitables should actually be generators / array of / list of
Awaitables?

In regards to Cancellable by Design. In the current state of PHP, we can
assume that if a function used to throw an Exception and a future version
stops throwing said exception it is not considered a BC Break. Of course,
throwing a *different exception* not part of the hierarchy is a BC break.
But when an exception signals "I cannot handle this" and a future version
becomes capable of handling it, that in essence is a feature/enhancement
and not treated as a BC break. With "Cancellation by Design" we are
expected that every coroutine be cancellable and that we must write try /
catch to design for cancellation. This seems to open up a different
development flow where catch blocks can be fundamentally part of the BC
promise. One possible alternative would be e.g. await(Awaitable $awaitable,
Closure $cancellation) where the cancellation of a coroutine would trigger
the specified Closure. Now, I don't want to dive too much into the
trade-offs of these options, what I want is to spark the idea that there
may be multiple ways to design cancellable coroutines. When I consider
that, plus the added fact that the RFC is very dense, extensive and hard to
digest, wouldn't it be best to postpone coroutine cancellations altogether?
The RFC itself states:

>  [...] read operations (database queries, API calls, file reads) are
typically as frequent as—or even more frequent than—write operations. Since
read operations generally don't modify state, they're inherently safe to
cancel without risking data corruption.

which not only I agree with, but also want us to focus on this very fact.
What if the first version of Async PHP provides userland with the ability
to trigger coroutines for reading purposes only? We will not forbid/prevent
anybody from shooting themselves if they want to, but we can still clearly
state the design principle that Async PHP is meant to spawn coroutines
cancellable by design. There will not be any coroutine markers in the
future nor there will be assumptions that coroutines written for the 1st
version of Async PHP must not be cancellable. The assumption is that the
first version of Async PHP should be treated as a way to perform read
operations only and a future RFC / enhancement will bring cancellation
capabilities (be it Closure, Try / Catch, what have you). My reasoning is
that this would further reduce the scope of the RFC while still introducing
real life useful async components to PHP, even if at a limited capacity. It
gives voters less concepts to understand, digest, agree on and approve and
it extends the opportunity to focus on specific deep aspects of Async PHP
in chunks and throughout different stages.

-- 
Marco Deleu

---

## #129007 — Edmond Dantes — 2025-10-30T14:34:00+00:00

URL: https://externals.io/message/129004#129007 · In reply to: #129006

Hi

> One minor question: is this section https://wiki.php.net/rfc/true_async#awaiting_a_result_with_cancellation named wrongly? I'm not sure how this snippet of code relates to cancellation.
Yes, second parameter is a CancellationToken. (spawn('sleep', 2)).

> What's the difference between Multishot Awaitables and Generators?
There’s nothing in common between them.
It’s better to think of asynchronous objects as components of an
EventDriven pattern.

> doesn't this mean that multishot awaitables are not really capable of being awaited anymore?
Exactly. It’s not needed for now.

> Shouldn't FutureLike be Awaitable and what has been described as Multishot awaitables should actually be generators / array of / list of Awaitables?
FutureLike is a child interface of Awaitables.

> we can assume that if a function used to throw an Exception and a future version stops throwing said exception it is not considered a BC Break.
This RFC does not change the behavior of existing functions. For
example, sleep works the same as before.
PHP functions that previously did not throw a CancellationError do not
throw it in this RFC either.
However, when you use functions (await example) that do throw these
exceptions, you handle them the same way as always. In that sense,
there’s no new paradigm.

> What if the first version of Async PHP provides userland with the ability to trigger coroutines for reading purposes only?

Sorry, but I couldn’t understand why this needs to be done.
There’s nothing terrible about canceling write operations — no
“shooting yourself in the foot” either. A program can terminate at any
moment; that’s perfectly normal.

The concept of Cancellation by Design isn’t about guns — it’s about
reducing code. That’s all.
In the Swift language, for example, a different concept is used:
cancellation is always written explicitly in the code, like this:

```swift
func fetchData() async throws -> String {
    for i in 1...5 {
        try Task.checkCancellation()
        print("Fetching chunk \(i)...")
        try await Task.sleep(nanoseconds: 500_000_000)
    }
    return "Data loaded"
}
```

The only question is about how much code you write and the likelihood
of errors. The more code you write, the higher the chance of making
one.

Write safety is a different topic; it concerns how code is implemented
at the lowest level, meaning the code that calls OS functions.
Cancelling a coroutine cannot interrupt a kernel-level write operation
— it can only interrupt waiting for the write, and what to do next is
decided by the user-level code.

The cancellation design was implemented as early as 2015 in Python
(and in other languages as well) and has worked perfectly since then.
For languages like PHP, it’s a convenient and, most importantly,
familiar mechanism. The real problem is that an exception can
accidentally be caught without exiting the coroutine. For example:
```php
catch (\Throwable $e) {
    Logger::log();
}
continue;
```

---

## #129034 — Dennis Birkholz — 2025-10-31T22:59:37+00:00

URL: https://externals.io/message/129004#129034 · In reply to: #129004

Hi Edmond,

Am 30.10.25 um 9:19 AM schrieb Edmond Dantes:
> Hi
>
> 1.5 RFC:
> https://wiki.php.net/rfc/true_async

first of all thank you for investing so much time and effort into 
improving PHP.

The True Async RFC changed a lot in the past iterations and removed a 
lot of related but tangential topics. I really appreciate your 
willingness to adapt to get the best possible outcome.

What I now see is as far as I understand essentially a Fiber 2.0 RFC so 
I wonder if it would not be better to improve the available Fibers 
instead of creating an incompatible second mechanism.

The Coroutine class is essentially a Fiber class that can be cancelled 
and restricted by a cancellation awaitable.
The Fiber class could get startWithTimeout($timeout, ...$args) and 
resumeWithTimeout($timeout, mixed $value = null) methods as well as a 
cancel() method.
It wouldn't be a Fiber in the pure compsci way any more but I am willing 
to accept that if it prevents us from having two ways for (semi) 
cooperative multitasking.

The part about how the Awaitable and FutureLike interfaces work is very 
unclear to me. They are there but they do not describe how they could be 
used in a truly multitasking fashion. That is somehow open to the 
Scheduler/Reactor which are not described to reduce the complexity.
The RFC as it is allows to `await(new Coroutine())` which is syntactical 
sugar for `$fiber = new Fiber(); $fiber->start(); while 
(!$fiber->isTerminated()) $fiber->resume();` So a followup RFC would 
need introduce this additional mechanism into these interfaces.

Also I do not really understand why the "cancellation" is an awaitable. 
If the provided awaitable is itself some infinitely blocking Coroutine 
(e.g. `while (true) {}`), how can the scheduler run the actual Coroutine 
and the "cancellation" awaitable to determine whether the Coroutine 
should be cancelled or not? As long as there is no multithreading, this 
does not make sense for me.

In addition, what happens if a Coroutine is suspended and is restarted 
again. Is the cancellation awaitable restarted? Or just continued?

I am really skeptical if the current RFC is the right way to go, 
establishing a Coroutine and Awaitable and FutureLike interfaces in 
competition to the existing Fiber.

I would rather see a step-by-step plan with gradual improvements like this:

1. Propose some changes to Fiber so it can be interrupted after a timer 
expired and it can be cancelled.

2. Add a unified polling mechanism for all kinds of IO events (timeouts 
and signals included) like Jakub's "Polling API".

3. Enhance the Fiber class so it can expose a PollHandle/Pollable that 
it is currently waiting on, either as a property of the Fiber 
(Fiber::$pollHandle) or as a `Fiber::suspendPolling(PollHandle 
$pollHandle, mixed $value = null)` method.

4. Now internal IO methods can be changed to start a pollable Fiber 
instead of blocking the execution if they are started in a specific way 
(e.g. by a then introduced spawn() call).

5. With all that in place, userland can now create their own 
Scheduler/Rector. The Core could also include a simple default 
implementation used the PollContext/PollWatcher in addition with a 
scheduling policy for other Fibers.

Kind regards
Dennis

---

## #129038 — Edmond Dantes — 2025-11-01T07:32:46+00:00

URL: https://externals.io/message/129004#129038 · In reply to: #129034

Hello Dennis.

> With all that in place, userland can now create their own Scheduler/Rector.

I once wrote about why such solutions are unsuccessful — and clearly
bad from PHP’s point of view.
But since I don’t remember where that text was, I’ll try to express it again.

Programming languages have levels of abstraction, which researchers
have been trying to quantify mathematically since the 1970s.
PHP is a high-level programming language with a relatively high degree
of abstraction, thanks to its memory management, built-in runtime, and
abstraction over the operating system.

Suppose someone created an RFC proposing to add assembly inserts into PHP.
Would you vote in favor of this RFC?
If not, why?

Most software — almost all of it — from operating systems to browsers,
is built on the principles of multilayered architecture,
where abstractions are separated into distinct layers.
This is done to reduce and control interdependencies, which directly
affects what are probably the three most important parameters in
programming:
the cost of code, the cost of debugging, and the cost of refactoring.

For this architecture to work, developers try to follow the **Strict
Layering** rule  (known by other terms in different contexts),
which states that code from a higher-level layer must not interact
with a lower-level layer while skipping the intermediate one.
Although this rule is almost always violated, adhering to it is
justified in most cases.

Assembly inserts in PHP violate the **Strict Layering** rule and give
the programmer the ability to completely break the language’s
operation, since they belong to the lowest layer.

A Fiber in PHP is a context that stores a pointer to the C stack, CPU
registers, and part of the VM state, combined with a generator.
Fibers cannot be used as coroutines because this approach is
inefficient in terms of performance and memory.
The reason is that a Fiber is an extremely low-level primitive — only
slightly higher than assembly.

Let’s recall what a full-fledged abstraction of asynchrony looks like
in any proper programming language:
https://editor.plantuml.com/uml/TLBDRjGm4BxFKunw0QJTvSu1LQfQgH9L4HLmTftPpQYE7SrCkXigtXqx8MxOYfF7zZVVZyUNQaviw0Be4yVUYUimS2GRUy97-iKa0COM2B-HyvPasmW_KyIh96cm3CMxr5004FBcuY4ZBwvFvFDTAgXeT39yVyEF91ykq6azUm74LLCbd41r1x__eNxmBJL389bGTOSlPxZPxOpwMvyBNkSOXbzIwWjgAWh9Exm9wOXfZxJ4WDUms-tdolS9tT6nuUt7UwH21ijDHbLl1HUJyNv48TUCw6kqIlkcOMGA3QQ8aKusom1a5aBXGsl5NOL3hJ9rD4b1NpKmy9xyw0FjuDPG1-qfDYk05fKvXuiD2kdGaOArrE6nfLZJ2lL9JASGfKztGBcXc3gpjamOtlw3DeKi_kCErPpH1lBYdpQJyjNNxoXqO3KItQtUPXu3AHxPMex8zb_bnMmTH9SYvrLnpu6m8VN2VJdOW76NXMPjvKDqGV6P7Tu_xE1d2UxYF5LCtWy5oJOFacdryrPUBdCrTE4F

Therefore, Fibers violate the **Strict Layering** principle, and PHP
has no way to prevent this — unlike Rust, for example, where you can
hide parts of the implementation within a crate (package).
Even in C++, there is no such violation — the programmer works with
the coroutine abstraction.

It is also important to understand the difference between PHP and
C++/Rust: PHP is a single-runtime language.
When you have multiple runtime libraries, for example asynchronous
ones, a segmentation problem arises:
you cannot simply use code written for runtime A in runtime B, because
the runtimes are incompatible!

What made PHP popular?
What made Go popular?
That’s right — the built-in runtime!
Just write code.

Just a week or two ago, I read an article from the Python community
discussing the problems caused by the segmentation of asynchronous
libraries.
And let me remind you, that Python has had built-in language-level
support for asynchrony since 2015.

So...
I’m convinced that PHP should remain a high-level language with a
built-in runtime (at least as long as it’s interpreted).
Attempts to create a “backdoor” in the language to let libraries
implement what should be written in C bring no benefit to PHP users.

After all, to use asynchrony, it’s not enough to just add `spawn` or coroutines.
Libraries and frameworks must also be adapted, and all of that takes time.
Go added more abstractions to the language to make writing business
logic easier.
Python will soon implement JIT.
People will choose the tool that “just works” with minimal effort and
they won’t care what it’s called.

---
Best regards,
Ed

---

## #129040 — Dennis Birkholz — 2025-11-01T13:15:09+00:00

URL: https://externals.io/message/129004#129040 · In reply to: #129038

Hi Edmond,

thank you for your reply.

Am 01.11.25 um 8:32 AM schrieb Edmond Dantes:
> A Fiber in PHP is a context that stores a pointer to the C stack, CPU
> registers, and part of the VM state, combined with a generator.
> Fibers cannot be used as coroutines because this approach is
> inefficient in terms of performance and memory.
> The reason is that a Fiber is an extremely low-level primitive — only
> slightly higher than assembly.
>
> Therefore, Fibers violate the **Strict Layering** principle ...

 From the standpoint of PHP language user, I have a completely different 
view on Fibers vs. Corotines.
They look very similar from the outside and if we talk about 
abstractions, that is the point that matters as the inner workings are 
hidden.

I really belief we should avoid fragmentation and enhance/adjust Fibers 
to meet the memory and performance requirements of a Coroutine.

Thanks
Dennis

---

## #129041 — Dennis Birkholz — 2025-11-01T13:17:04+00:00

URL: https://externals.io/message/129004#129041 · In reply to: #129034

Hi Edmond,

could you please clarify these two questions? Thanks.

Am 31.10.25 um 11:59 PM schrieb Dennis Birkholz:
> Also I do not really understand why the "cancellation" is an 
> awaitable. If the provided awaitable is itself some infinitely 
> blocking Coroutine (e.g. `while (true) {}`), how can the scheduler run 
> the actual Coroutine and the "cancellation" awaitable to determine 
> whether the Coroutine should be cancelled or not? As long as there is 
> no multithreading, this does not make sense for me.
>
> In addition, what happens if a Coroutine is suspended and is restarted 
> again. Is the cancellation awaitable restarted? Or just continued?

Kind regards
Dennis

---

## #129042 — Edmond Dantes — 2025-11-01T16:00:10+00:00

URL: https://externals.io/message/129004#129042 · In reply to: #129040

>  From the standpoint of PHP language user, I have a completely different view on Fibers vs. Corotines.
That’s sad.

> They look very similar from the outside
Coroutines and Fibers have completely different behavior. I hope
you’re not comparing them just by appearance?

> I really belief we should avoid fragmentation and enhance/adjust Fibers to meet the memory and performance requirements of a Coroutine.
But the problem has already happened, and it’s not directly related to this RFC.
Of course, there’s a possibility to bridge the two worlds by calling
PHP functions from C, but as I’ve said before: just because something
can be done doesn’t mean it should be done.

> If the provided awaitable is itself some infinitely blocking Coroutine (e.g. while (true) {}),

If you have a coroutine with an infinite loop, it means other
coroutines will never get control.
(more about it by searching for the keyword: “concurrency")

The RFC contains an example that isn’t very elegant from a semantic
point of view, but is completely correct in terms of logic:
```php
// Await task 1, but no longer than 5 seconds.
await($task1, spawn(sleep(...), 5));
```

And here’s another piece of code (Async\Signal is not present in the
RFC, but it’s entirely possible.):
```php
// Await task 1 until a signal occurs.
await($task1, new Async\Signal(SIG_TERM));
```

> In addition, what happens if a Coroutine is suspended and is restarted again.

The Await function waits for the coroutine to complete.
The suspended state does not affect the waiting process.
The wait is interrupted for two reasons: an unhandled exception or the
coroutine’s completion.

All of this is described in the RFC: https://wiki.php.net/rfc/true_async#await

---
Ed

---

## #129044 — Larry Garfield — 2025-11-01T17:59:06+00:00

URL: https://externals.io/message/129004#129044 · In reply to: #129038

> So...
> I’m convinced that PHP should remain a high-level language with a
> built-in runtime (at least as long as it’s interpreted).
> Attempts to create a “backdoor” in the language to let libraries
> implement what should be written in C bring no benefit to PHP users.

In concept, I agree.  Which is part of why I want to see an Async RFC that goes even higher than the current one, not lower. :-)

But that is separate from the question of whether it's possible to build on Fibers, rather than effectively deprecate them in practice if not in name.

--Larry Garfield

---

## #129047 — Edmond Dantes — 2025-11-01T19:41:02+00:00

URL: https://externals.io/message/129004#129047 · In reply to: #129044

Hi

> But that is separate from the question of whether it's possible to build on Fibers, rather than effectively deprecate them in practice if not in name.

Originally, Fiber was proposed with a Scheduler, but the Scheduler was
refused.
To allow Fiber switching without a Scheduler, they were made
**symmetric** (so that the switching code could do it manually).
This, in turn, creates a problem when trying to add a Scheduler later.

To create coroutines, you need to write the "switching code".
But to write the switching code, Fibers must be allowed to switch arbitrarily.
And for Fibers to switch arbitrarily, backward compatibility must be broken.

What could be reused? The context-switching code and the observer
component handlers — these were reused.
The issue isn’t that Fiber behavior can’t be changed, but that it
should be **hidden as an internal component**.
There should be **no access to it from PHP code**.

The experience with Fiber shows that language features like asynchrony
must be **designed as a whole from the start** — thoughtfully and
consistently.
You can’t make a language "a little" asynchronous today and a bit
"more" tomorrow:

1. Critical components must be designed **in advance** to understand
how they interact.
2. They must be placed within the **same layer of abstraction**.
3. Use cases must be thought out in advance.

---
Best regards
Ed

---

## #129126 — luisvscbarros@gmail.com — 2025-11-07T06:22:25+00:00

URL: https://externals.io/message/129004#129126 · In reply to: #129004

Hi Edmond,

First of all, sorry for my bad English, and thanks a lot for the huge 
amount of work you’ve put into this proposal.
You researched, wrote the RFC, implemented it, and answered tons of 
questions. Really impressive.

I have one suggestion and two small questions.

*Suggestion*

Maybe keep the base |Awaitable| internal and expose two userland 
interfaces that match the two cases described in the RFC:

|// Single state change, idempotent read, same result on each await 
interface Future extends Awaitable {} // Multiple state changes, each 
await may observe a new state interface Streamable extends Awaitable {} |

This makes the single-shot vs multi-shot difference explicit and easier 
for tools and libraries to reason about.
Later on, it could even be extended with something like:

|interface Retryable extends Awaitable {}|

*Questions (self-cancellation)*

 1.

    What happens here?

|use function Async\spawn; use function Async\suspend; $coroutine = 
spawn(function() use (&$coroutine) { $coroutine->cancel(new 
\Async\CancellationError("Self-cancelled")); echo "Before suspend\n"; 
suspend(); echo "After suspend\n"; // should this run? return 
"completed"; }); await($coroutine); |

Can a cancelled coroutine suspend?
And if a function that yields is called after the cancel, should that 
suspension still happen?

 2.

    And what about this one?

|use function Async\spawn; $coroutine2 = spawn(function() use 
(&$coroutine2) { $coroutine2->cancel(new 
\Async\CancellationError("Self-cancelled")); echo "Before exception\n"; 
throw new \RuntimeException("boom after cancel"); }); await($coroutine2); |

Which error does |await()| throw in this case — |CancellationError| or 
|RuntimeException|?
It’d be great to clarify that in the docs, since it affects where people 
put cleanup, logging, etc.

Again, thanks for the work, especially on such an important feature for 
PHP’s future.
Hope to see it in php-src soon.

Best,
*Luís Vinícius*

---

## #129214 — Edmond Dantes — 2025-11-13T09:01:58+00:00

URL: https://externals.io/message/129004#129214 · In reply to: #129004

Hello all.

Today marks two weeks since the RFC was published.

I need to apply a few minor fixes that Luis pointed out.

If anyone else is working on comments for the RFC, please let me know.
If there are no objections, we can start the vote on Monday.

Best regards, Ed

---

## #129215 — tim@bastelstu.be — 2025-11-13T10:00:08+00:00

URL: https://externals.io/message/129004#129215 · In reply to: #129214

Hi

Given your planned timeline of voting, I wanted to chime in here before 
my vacation. I'll likely only see the reply on Monday morning.


> If anyone else is working on comments for the RFC, please let me know.
> If there are no objections, we can start the vote on Monday.

It appears that you believe that the RFC and the proposal finally 
settled. I frankly lost track of what has been discussed in all the 
different discussion threads related to various Async RFCs.

What I am missing from the RFC text is some kind of "Executive Summary" 
to make it clear what *is* and what *is not* actually being proposed. 
The RFC starts of with goals and a glossary that primarily explains by 
means of an example.

This makes it hard for me to see what I am actually voting for (and what 
I am not), especially after the many changes to refine the RFC. I would 
suggest to add a “full stub” (as suggested in the RFC template 
https://wiki.php.net/rfc/template#proposal) at the start and also to 
shortly explain what is proposed and what is left untouched (e.g. the 
RFC already mentions that file_get_contents is not proposed to change, 
but that is easy to miss without carefully reading everything) before 
diving into the details for each of the functions.

With regard to the relationship with fibers, it is not clear to me why 
e.g. Fiber::suspend() could map to Async\suspend() and why the Async 
event loop couldn't call ->resume() on suspended Fibers. Elaborating a 
little more would be helpful I think.

Also, please make sure to add the “Abstain” option to the vote 
(https://wiki.php.net/rfc/rfc_vote_abstain).

Best regards
Tim Düsterhus

---

## #129216 — Edmond Dantes — 2025-11-13T10:26:58+00:00

URL: https://externals.io/message/129004#129216 · In reply to: #129215

Hello, Tim.

> What I am missing from the RFC text is some kind of "Executive Summary"
> to make it clear what *is* and what *is not* actually being proposed

I’ll try to look through the text again to see what exactly might be
unclear. Although to be honest, I also don’t really understand what
exactly is unclear.

> This makes it hard for me to see what I am actually voting for
I suggest we do it this way. I’ll write a summary here, and if needed
we can add some of these phrases to the RFC.
I have an idea to format the summary as questions and answers. That
will probably make it easier to understand.

>  I would suggest to add a “full stub”
+
> Also, please make sure to add the “Abstain” option to the vote
I will do it, thanks

> With regard to the relationship with fibers
I will also take these questions into account in the next message.

Thanks, Ed

---

## #129217 — Jakub Zelenka — 2025-11-13T10:30:06+00:00

URL: https://externals.io/message/129004#129217 · In reply to: #129214

Hi,



> Hello all.
>
> Today marks two weeks since the RFC was published.
>
> I need to apply a few minor fixes that Luis pointed out.
>
> If anyone else is working on comments for the RFC, please let me know.
> If there are no objections, we can start the vote on Monday.
>
>
I thought about it and I think we should have this with implementation
otherwise the whole thing is kind of pointless because we might not get it
merged if some internals disagreement happens. It will be also impossible
to get anything bigger than what is proposed now reviewed (read that we
won't be likely able to merge the complete implementation in one go). In
other words if this passes, it will just means that the API is ok but there
is nothing actionable. In addition, I think some people might be even
voting against it if there is no implementation that they can review.

It means there should be a PR implementing exactly what is in this RFC
(minimal stripped version of your current implementation) IMO.

Cheers

Jakub

---

## #129218 — Edmond Dantes — 2025-11-13T10:44:31+00:00

URL: https://externals.io/message/129004#129218 · In reply to: #129217

Hello, Jakub.

> It means there should be a PR implementing exactly what is in this RFC (minimal stripped version of your current implementation) IMO.

This RFC includes not only the API, but also the Scheduler, Reactor,
and non-blocking versions of PHP functions. Removing Scope from the
public classes doesn’t really change that.
Are you saying that some other implementation is needed as well?

Best regards, Ed

---

## #129219 — Edmond Dantes — 2025-11-13T13:08:29+00:00

URL: https://externals.io/message/129004#129219 · In reply to: #129215

Hello.

Mini Faq: https://github.com/true-async/php-true-async-rfc/blob/main/faq.md
Text here:

## Executive Summary: What This RFC Proposes

This RFC proposes adding **built-in concurrency support** to PHP
through two core components:

### 1. Coroutines via `spawn()`

Launch any PHP function as a lightweight coroutine that can be
suspended and resumed:
```php
use function Async\spawn;
use function Async\await;

$coroutine = spawn(file_get_contents(...), 'https://php.net');
$result = await($coroutine);
```

### 2. Non-blocking I/O Functions
**50+ existing PHP functions** automatically become non-blocking when
used inside coroutines:
- **Database**: PDO MySQL, MySQLi operations
- **Network**: CURL, sockets, streams, DNS lookups
- **Files**: `file_get_contents()`, `fread()`, `fwrite()`
- **Process**: `exec()`, `shell_exec()`, `proc_open()`
- **Timers**: `sleep()`, `usleep()`

**Key principle:** From the developer's perspective, these functions
work identically to their synchronous versions.
The difference is that they suspend only the current coroutine instead
of blocking the entire PHP process.

See full list: https://github.com/true-async/php-async#adapted-php-functions

### What This RFC Does NOT Propose
- **No changes to existing synchronous behavior** - code without
coroutines works exactly as before
- **No new syntax keywords** - uses function calls (`spawn()`,
`await()`, `suspend()`)
- **No changes to Fiber API** - Fibers and True Async are mutually
exclusive by design
- **No structured concurrency primitives** - covered in separate
[Scope RFC](https://wiki.php.net/rfc/true_async_scope)

## General Questions

### Q: What is the main goal of this RFC?

**A:** The RFC aims to provide a standardized way to write concurrent
code in PHP without requiring developers
to rewrite existing synchronous code. The key value proposition is
that existing code works **exactly the same**
inside a coroutine without modifications, unlike explicit async/await models.

### Q: How is this different from Fibers?

**A:** Fibers and True Async serve fundamentally different purposes
and cannot coexist:

**Fibers:**
- Low-level symmetric execution contexts
- Programmer explicitly controls switching (`$fiber->resume()`,
`Fiber::suspend()`)
- Direct access to execution stack management
- Suitable for building custom scheduling solutions

**True Async:**
- High-level asymmetric coroutines
- Automatic switching managed by the scheduler
- Transparent to the developer
- Designed for business logic, not infrastructure

**Why they can't work together:**

1. **Resource conflicts**: Both manage the same low-level resources
(execution context, CPU stack) in incompatible ways
2. **Architectural incompatibility**: Mixing symmetric (Fibers) and
asymmetric (coroutines) models creates unpredictable behavior
3. **Abstraction level**: Fibers expose low-level primitives in a
high-level language, violating the "Strict Layering" principle

**Why not map Fiber::suspend() to Async\suspend()?**

This would create a leaky abstraction:
- Fibers require explicit scheduling decisions (who to resume? when?)
- True Async scheduler makes these decisions automatically
- Mixing both models would break scheduler guarantees and lead to race
conditions
- The execution models are fundamentally incompatible (symmetric vs asymmetric)

If you need Fibers' explicit control, use Fibers.
If you want automatic concurrency for I/O-bound applications, use True Async.
Attempting to unify them would result in a solution that's neither
simple nor safe.

### Q: Isn't this just Fibers 2.0?

**A:** No. While both deal with execution contexts:
- Fibers require explicit switching and manual control
- True Async provides automatic scheduling and high-level primitives
- They solve different problems at different abstraction levels
- They are mutually exclusive by design

### Q: Can I use this with FPM?

**A:** Yes! True Async works in all execution modes including FPM.
The reactor activates within the context of
`php_request_startup/php_request_shutdown()`,
requiring no SAPI modifications.

### Q: What about `exit` and `die`?

**A:** They always trigger **Graceful Shutdown** mode:
- All coroutines in globalScope are cancelled
- Application continues execution without restrictions to shut down naturally
- This allows proper cleanup operations

### Q: Do I need to rewrite my existing code?

**A:** No. The main value of this implementation is that existing
synchronous code works inside coroutines without modification.
You can gradually adopt async features where beneficial.

### Q: How does this RFC affect I/O functions?

**A:** From the coroutine's perspective, I/O functions **do not change
their behavior**
they work exactly as they always have.
However, functions that previously blocked the entire PHP process now
only suspend the current coroutine,
allowing other coroutines to continue executing.

----
Best regards, Ed

---

## #129220 — Jakub Zelenka — 2025-11-13T14:41:20+00:00

URL: https://externals.io/message/129004#129220 · In reply to: #129218

Hi,



> Hello, Jakub.
>
> > […]
> (minimal stripped version of your current implementation) IMO.
>
> This RFC includes not only the API, but also the Scheduler, Reactor,
> and non-blocking versions of PHP functions. Removing Scope from the
> public classes doesn’t really change that.
> Are you saying that some other implementation is needed as well?
>
>
I think it would be good to see the implementation that can cover the
currently proposed API and try to strip it as much as possible so it
doesn't contain much more than that. We saw that PR for the async API was
already quite big and we didn't really get any agreement there partially
also because there was no user of that and it was not possible to have any
tests for it (without writing them in C). So what I'm thinking is that if
some minimal version that implements just this (e.g. reactor can be just
dummy because there is no io atm. and other things can be stripped too),
then the voters would get better idea what they are dealing with and could
even try it out.

Cheers

Jakub

---

## #129221 — Edmond Dantes — 2025-11-13T15:25:09+00:00

URL: https://externals.io/message/129004#129221 · In reply to: #129220

Hello Jakub.

> I think it would be good to see the implementation that can cover the currently proposed API and try to strip it as much as possible so it doesn't contain much more than that. We saw that PR for the async API was already quite
> big and we didn't really get any agreement there partially also because there was no user of that and it was not possible to have any tests for it (without writing them in C).
> So what I'm thinking is that if some minimal version that implements just this (e.g. reactor can be just dummy because there is no io atm. and other things can be stripped too), then the voters would get better idea what they are > dealing with and could even try it out.

I understand what you mean.

** Regarding simplifying the code.**
Any “simplification” essentially comes down to removing stub files and
the C classes that implement the PHP classes. This is a relatively
small part of the project.
For example, removing Scope from the C code doesn’t make much sense,
because it turned out (even unintentionally) to be a very convenient
structure for tracking a group of coroutines.
In other words, no major changes to the code are expected before the
PR review begins.

** Reactor. **
Since the reactor uses libUV and we currently do not plan to provide a
pure-C implementation, we agreed to move it into a separate library.

** Testing. **
Some functions that do not involve I/O can be covered by unit tests.
This is a small portion of the API.
However, covering all the remaining code that performs I/O with unit
tests is not practical. We could try to emulate the OS and so on… but
I think you understand that the result is not worth the effort.
This means we cannot avoid integration tests.

P.S. Personally, I would prefer to agree on the PR first and the RFC
afterwards. As I mentioned earlier, the code is more important than
the RFC, because it defines the real relationships and logic, while
the RFC only “describes” them. But we live in a world that follows its
own rules.

--- Ed

---

## #129224 — Edmond Dantes — 2025-11-14T09:49:52+00:00

URL: https://externals.io/message/129004#129224 · In reply to: #129214

Hello all.

I’ve updated the RFC by adding a brief summary at the very beginning
and adjusting the voting section.

As far as I understand, opening the vote requires creating a separate
page on the Wiki. For some reason, I couldn’t find clear instructions
for this in the documentation, which is a bit surprising.

Regarding the timeline, there is no need to rush. Someone may still
want to share their thoughts and simply hasn’t had the chance yet.
Therefore, we can extend the period until next Thursday. In the
meantime, I may also find a few more issues in the document.

---
Best regards, Ed

---

## #129225 — Rowan Tommins [IMSoP] — 2025-11-14T19:29:27+00:00

URL: https://externals.io/message/129004#129225 · In reply to: #129224

>As far as I understand, opening the vote requires creating a separate
>page on the Wiki. For some reason, I couldn’t find clear instructions
>for this in the documentation, which is a bit surprising.

The voting stage is described in step 6 of the How-To here: https://wiki.php.net/rfc/howto

There's no separate page, you just edit the attributes on the voting widget tag. You can see how it looks on the two RFCs that are currently "in voting" on the RFC index: https://wiki.php.net/rfc



Rowan Tommins
[IMSoP]

---

## #129228 — Rob Landers — 2025-11-15T11:37:45+00:00

URL: https://externals.io/message/129004#129228 · In reply to: #129214

> Hello all.
> 
> Today marks two weeks since the RFC was published.
> 
> I need to apply a few minor fixes that Luis pointed out.
> 
> If anyone else is working on comments for the RFC, please let me know.
> If there are no objections, we can start the vote on Monday.
> 
> Best regards, Ed

I have concerns about the clarity of when suspension occurs in this RFC.

The RFC states as a core goal:

"Code that was originally written and intended to run outside of a Coroutine must work EXACTLY THE SAME inside a Coroutine without modifications."

And:

"A PHP developer should not have to think about how Coroutine switch and should not need to manage their switching—except in special cases where they consciously choose to intervene in this logic."

However, the RFC doesn’t clearly define what these "special cases" are or provide guidance on when developers need to intervene.

Specific questions:

1. CPU-bound operations: If I have a tight loop processing data in memory (no I/O), will it monopolise the coroutine scheduler? Do I need to manually insert `suspend()` calls? How do I know when and where?
2. The RFC suggests that existing PHP functions won’t automatically be non-blocking. So which will? Is there a way to identify suspension points at the language/API level?
3. Performance implications: Without knowing where suspensions occur, how do developers avoid either:
  - Starving other coroutines (too few suspensions)
  - Degrading performance (too many suspensions)

With explicit async/await ("coloured functions"), developers know exactly where suspension can occur. This RFC’s implicit model seems convenient, but without clear rules about suspension points, I’m unclear how developers can write correct concurrent code or reason about performance.

Could the RFC clarify the rules for when automatic suspension occurs versus when manual `suspend()` calls are required? Is this RFC following Go’s model where suspension timing is an implementation detail developers shouldn’t rely on? If so, that should be stated explicitly. Keep in mind that Go didn’t start that way and took nearly a decade to get there. Earlier versions of Go explicitly stated where suspensions were.

— Rob

---

## #129230 — Edmond Dantes — 2025-11-15T12:16:14+00:00

URL: https://externals.io/message/129004#129230 · In reply to: #129228

Hello all.

Some of these questions sound familiar. Let’s try to sort them out.

> If I have a tight loop processing data in memory (no I/O), will it monopolise the coroutine scheduler? Do I need to manually insert suspend() calls? How do I know when and where?

A coroutine must yield control on its own. If it keeps it through an
endless loop, then it will be the only one running.

> The RFC suggests that existing PHP functions won’t automatically be non-blocking. So which will? Is there a way to identify suspension points at the language/API level?

The RFC does not say that. PHP I/O functions automatically become
non-blocking relative to the whole process. In other words, an I/O
function calls suspend() on its own when needed. The programmer writes
code exactly as before, under the illusion that operations are
executed one after another.

> Performance implications: Without knowing where suspensions occur, how do developers avoid either:

In most cases, this is not the developer’s concern. Situations where
performance is critical should be handled with dedicated tools.
A PHP developer should not have to drop down to the C level. Properly
designed abstractions must provide the required performance.

I can already anticipate the question: but a developer could write
something like “for i < 10000 suspend” or something similar.
The answer is this: a developer must know how to use abstractions. As
always. Everywhere. In any area of programming.
It’s just as important as respecting proper layering in code.

Provided that PHP does not try to play the role of a C-level language
(there have already been such attempts, and they keep resurfacing),
and does not try to play a web server or a database system.
For most web scenarios, the current approach is more than sufficient.
This has been proven by Swoole, which has been on the market for many
years. Therefore, performance questions are outside the scope of this
RFC.

As for the concurrency model, let me remind you that Go has true
multitasking. Goroutines in Go, although they have a “synthetic”
stack. But you already know all this well.
This RFC and its implementation describe coroutines in a single
thread. That is very far from what Go provides.

There is no preemptive multitasking in this RFC because it is
completely unrelated.
This RFC and its implementation provide cooperative concurrency in a
single thread, where coroutine code yields control on its own.
Why was this model chosen? The simple answer is: because it is the
only one that can realistically be implemented within a finite
timeframe.

Any more questions?

-- Ed

---

## #129231 — Rob Landers — 2025-11-15T14:09:51+00:00

URL: https://externals.io/message/129004#129231 · In reply to: #129230

> Hello all.
> 
> Some of these questions sound familiar. Let’s try to sort them out.
> 
> > […]
> 
> A coroutine must yield control on its own. If it keeps it through an
> endless loop, then it will be the only one running.
> 
> > […]
> 
> The RFC does not say that. PHP I/O functions automatically become
> non-blocking relative to the whole process. In other words, an I/O
> function calls suspend() on its own when needed. The programmer writes
> code exactly as before, under the illusion that operations are
> executed one after another.
> 
> > […]
> 
> In most cases, this is not the developer’s concern. Situations where
> performance is critical should be handled with dedicated tools.
> A PHP developer should not have to drop down to the C level. Properly
> designed abstractions must provide the required performance.
> 
> I can already anticipate the question: but a developer could write
> something like “for i < 10000 suspend” or something similar.
> The answer is this: a developer must know how to use abstractions. As
> always. Everywhere. In any area of programming.
> It’s just as important as respecting proper layering in code.
> 
> Provided that PHP does not try to play the role of a C-level language
> (there have already been such attempts, and they keep resurfacing),
> and does not try to play a web server or a database system.
> For most web scenarios, the current approach is more than sufficient.
> This has been proven by Swoole, which has been on the market for many
> years. Therefore, performance questions are outside the scope of this
> RFC.
> 
> As for the concurrency model, let me remind you that Go has true
> multitasking. Goroutines in Go, although they have a “synthetic”
> stack. But you already know all this well.
> This RFC and its implementation describe coroutines in a single
> thread. That is very far from what Go provides.
> 
> There is no preemptive multitasking in this RFC because it is
> completely unrelated.
> This RFC and its implementation provide cooperative concurrency in a
> single thread, where coroutine code yields control on its own.
> Why was this model chosen? The simple answer is: because it is the
> only one that can realistically be implemented within a finite
> timeframe.
> 
> Any more questions?
> 
> -- Ed

Hey Ed,

I feel like we’re talking past each other a bit. I’m not questioning the choice of a cooperative scheduler, that’s totally fine, I’m trying to understand what the actual suspension points are. Every other language/runtime with cooperative concurrency spells this out, because without it developers can’t reason about performance or why a deadlock is happening.

Based on the conversation so far, I’d imagine the list to look something like:

- network i/o (streams/sockets/dns/curl/etc)
- sleeps
- subprocess waits? `proc_open` and friends?
- extensions with a reactor implementation
- awaiting `FutureLike`
- `suspend()`

If that’s the intended model, it’d help to have that spelled out directly; it makes it immediately clear which functions can or will suspend and prevents surprises.

I also think the RFC needs at least minimal wording about scheduler guarantees, even if the details are implementation-specific. For example, is the scheduler run-to-suspend? FIFO or round-robin wakeup? And non-preemptive behaviour only appears here in the thread. It isn’t mentioned in the RFC itself. That’s important for people writing long, CPU-bound loops, since nothing will interrupt them unless they explicitly yield.

Lastly, cancellation during a syscall is still unclear. If a coroutine is cancelled while something like `fwrite()` or a DB write is in progress, what should happen? Does `fwrite()` still return the number of bytes written? Does it throw? For write-operations in particular, this affects whether applications can maintain a consistent state.

Clarifying these points would really help people understand how to reason about concurrency with this API.

— Rob

---

## #129232 — Edmond Dantes — 2025-11-15T14:41:11+00:00

URL: https://externals.io/message/129004#129232 · In reply to: #129231

Hello.

> Based on the conversation so far, I’d imagine the list to look something like:

Yes, that’s absolutely correct. When a programmer uses an operation
that would normally block the entire thread, control is handed over to
the Scheduler instead.
The suspend function is called inside all of these operations.

> If that’s the intended model, it’d help to have that spelled out directly; it makes it immediately clear which functions can or will suspend and prevents surprises.

In the Async implementation, it will be specified which functions are supported.

> I also think the RFC needs at least minimal wording about scheduler guarantees, even if the details are implementation-specific.
The Scheduler guarantees that a coroutine will be invoked if it is in the queue.

>  For example, is the scheduler run-to-suspend? FIFO or round-robin wakeup? And non-preemptive behaviour only appears here in the thread. It isn’t mentioned in the RFC itself.

In Go, for example, when it was still cooperative, these details were
also not part of any public contract. The only guarantee Go provided
was that a coroutine would not be interrupted arbitrarily. The same
applies to this RFC: coroutines are interrupted only at designated
suspension points.
However, neither Go nor any other language exposes the internal
details of the Scheduler as part of a public contract, because those
details may change without notice.

> That’s important for people writing long, CPU-bound loops, since nothing will interrupt them unless they explicitly yield.
Hypothetically, in the future it may become possible to interrupt
loops, just like Go eventually did. This would likely require an
additional RFC. PHP does have the ability to interrupt a loop at any
point, but most likely only for terminating execution.
This RFC does nothing of the sort.

> Lastly, cancellation during a syscall is still unclear. If a coroutine is cancelled while something like `fwrite()` or a DB write is in progress, what should happen?
> Does `fwrite()` still return the number of bytes written? Does it throw? For write-operations in particular, this affects whether applications can maintain a consistent state.

If the write operation is interrupted, the function will return an
error according to its contract. In this case, it will return false.

> Clarifying these points would really help people understand how to reason about concurrency with this API.

This is described in the document.
There is, of course, a nuance regarding extended error descriptions,
but at the moment no such changes are planned.

---

Next page: https://externals.io/message/129004.md?page=2
