# PHP 2^3

- Thread: https://externals.io/message/102480
- Original archive: https://news-web.php.net/php.internals/102480
- Started by Dmitry Stogov on 2018-06-27T06:48:04+00:00
- Messages: 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

---

## #102480 — Dmitry Stogov — 2018-06-27T06:48:04+00:00

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

Hi Niklas,


Hey Dmitry,

>
> hi Aaron,
>
>
> 
>
> > […]
>
> Regarding async, are you referring to the Fiber extension? In my opinion, fibers would be the best approach for async in PHP. After using async/await in other languages, it doesn't offer a significant gain over what's already possible in PHP with generator-based coroutines in Amp. Using the fiber extension and a green-thread library that resumes fibers based on promise resolution [1], we've been able to write async code without the need for yield or await [2], with async functions having proper return types (i.e. not promise, but the type the promise would resolve to). Joel Wurtz has also put together a PoC of using Doctrine asynchronously using the fiber extension and Amp [3].
>
> Febers/couroutines is one of the goals.
> Another possible goal — event-loop primitives for internal extensions (e.g. async DB queries)
> I think, we don't need async/await keywords or promises implementation in core
> Anyway, as an expert in async PHP, you should tell us, what you really need from the PHP core...
> I would be glad to hear your oppinion.
>
> Thanks. Dmitry.

Fibers are the major feature we're looking forward to, because it
allows async I/O in places that do not account for async, e.g. also
re-using interfaces designed for sync applications. Apart from that,
we want to avoid the boilerplate we currently have to write, i.e.
Amp\call wrapping a generator function.

We already have ext/fiber proposal and additioal branch implementing stack-full fibers.
I think, we'll build fibers in the PHP core reusing this work, keeping the proposed API and behavior.


We think that a methodless "Promise" / "Awaitable" type + fibers
implemented with keywords are the preferred way over the current Fiber
draft in the long run.

This is too abstract.
What keywords do you like for fibers and why do we need them?
Why do we need Promise/Awaitable in the core?
If you have concrete solution (just API), lets discuss it in separate email thread.


Fibers allow for transparent async I/O, which means we could maybe
transparently upgrade file_get_contents and others to use async I/O in
future versions, but something like that obviously needs an event-loop
in core.

May be yes, may be not. Event-loop may be implemented in PHP, but perform integration with internal functions, through special interface (e.g. allow internal function to post compltion events  into the event queue). Anyway, there is no any formed plan about event-loop in core. I hope, the experience of AMP team, would help us to make good decision. And I count on Bob, regarding implementation.

Thanks. Dmitry.


That said, it's definitely something we want to push to PHP 8, but
nothing that has to be discussed in too much detail in this thread.

Regards, Niklas

---

## #102497 — Aaron Piotrowski — 2018-06-27T16:15:04+00:00

URL: https://externals.io/message/102480#102497 · In reply to: #102480

> 
> 
> Hi Niklas,
> 
> Fibers are the major feature we're looking forward to, because it
> allows async I/O in places that do not account for async, e.g. also
> re-using interfaces designed for sync applications. Apart from that,
> we want to avoid the boilerplate we currently have to write, i.e.
> Amp\call wrapping a generator function.
> 
> We already have ext/fiber proposal and additioal branch implementing stack-full fibers.
> I think, we'll build fibers in the PHP core reusing this work, keeping the proposed API and behavior.
> 

I concur with Niklas - Fibers are the major feature needed, the stack-full branch in particular. Being able to reuse so much existing PHP code is particularly exciting. Most modern, testable PHP code performing IO should allow for async IO implementations, since IO should be mockable to be properly tested.

> 
> We think that a methodless "Promise" / "Awaitable" type + fibers
> implemented with keywords are the preferred way over the current Fiber
> draft in the long run.
> 
> This is too abstract.
> What keywords do you like for fibers and why do we need them?
> Why do we need Promise/Awaitable in the core?
> If you have concrete solution (just API), lets discuss it in separate email thread.

Niklas and/or I will put something together and start a new thread.

Regards,
Aaron Piotrowski
