Closed thinker-gao closed 3 years ago
@thinker-gao Yes, we plan to do that. You can find the draft of the RFC at https://github.com/trowski/fiber-rfc/blob/master/rfc.md
Does this extension support windows?
Yes, the extension supports Windows.
Thank you for your contribution to php. In addition, I found some similar projects, such as swoole and swow. I hope to bring you reference and improvement. Thank you again for your contribution. swoole:https://github.com/swoole/swoole-src swow:https://github.com/swow/swow
@thinker-gao We're aware of Swoole, but I wasn't aware of swow, thanks. Swoole seems to follow a different approach, especially considering channels are the only communication between coroutines.
As the questions have been answered, I'll close this issue.
@trowski @kelunik hi! I have a few questions too. I am advanced user of Swoole. And I'm interested in native PHP coroutines.
Channel based messaging between coroutines and between timer -> coroutine?
Sure, there's an implementation in https://github.com/amphp/parallel. What do you mean with timer -> coroutine?
Coroutine context - user level access to coroutine (fiber) context with an ability to read/write custom data?
Yes, you can build this using Fiber::this()
and weak maps.
Ability to wait one of multiple communication operations (IO, channels, timers and etc) - tour.golang.org/concurrency/5
This can easily be implemented using promises in userland, see e.g. Amp\Promise\first()
.
Possibility to share data between threads?
Yes, PHP keeps being single threaded and any data can be accessed normally. Fibers are 1:n scheduled on a kernel thread, not n:m on different kernel threads.
Do you have any plans to make scheduler in a multi threading way, like Golang does?
No, see above.
And also I have to ask about debugging, is it possible to list all coroutines and see their stack trace?
I think this isn't possible right now, but it's possible to build this into a debugger like xdebug or provide it as core functionality in the future.
How do you plan do detect dead locks?
There aren't any locks, as only one fiber is running at any given time. Thus, there's no need for any dead lock detection.
@kelunik thanks for your answers!
What do you mean with timer -> coroutine?
I mean communication from timer tick handler with some coroutine that is working in background. The answer for this question is https://github.com/amphp/parallel/blob/master/lib/Sync/Channel.php
Yes, you can build this using Fiber::this() and weak maps.
Did I understand correctly that I can put some data to fiber context and it will be automatically freed on fiber exit?
-- P.S. I would like to express my gratitude to you guys. You're really making PHP better and doing it in a right way, thanks!
Yes, communication isn't limited and works normally. The version you've linked isn't based on fibers, take a look at the v2 branch for that.
You can't store data in the fiber context, but you can build something similar with weak maps, yes.
First of all, thank you for your contribution to php. I would like to ask if this extension will be merged into the main branch of php via rfc? Does this extension support windows?