Hi Aaron Piotrowski, > I would like to introduce an RFC for adding full-stack fibers to PHP: > https://wiki.php.net/rfc/fibers > > Fibers are primarily used to implement green-threads or coroutines for > asynchronous I/O. Fibers are similar to threads, except fibers exist within a > single thread and require cooperative scheduling of the fibers by the > process. Since fibers do not require a full CPU context switch, they are > lightweight and more performant than multi-processing or threading for > awaiting I/O. > > An implementation as an extension is at https://github.com/amphp/ext-fiber > > Fibers are a complex feature. The RFC contains many examples and links to > code using fibers to help explain and demonstrate what is possible, however > I’m certain many more questions and concerns will arise. Looking forward to > feedback and discussion.
I took a look at the amphp/ext-fiber repo a few weeks ago - nothing stood out as a major concern but I'm only moderately familiar with threading, A minor comment is that it'd be easier to read the phpt test cases if the `--EXPECTF--` section included the file's basename in the test output of error traces instead of just `%s`, etc. (e.g. tests/002-throw.phpt) ``` Stack trace: #0 %s(%d): {closure}() #1 %s(%d): Loop->tick() #2 %s(%d): Loop->run() ... ``` I didn't see in the test cases/rfc: How do the `zend_try`/`zend_catch`/`zend_end_try` macros and `zend_error_noreturn` macros get handled after a fatal error? I'm not 100% sure - I think those use setjmp/longjmp internally - will fatal errors continue to work if there's a fatal error from within a fiber. (e.g. `require_once` on a file with a compile-time fatal error such as duplicate parameters). I forget exactly how they work, e.g. in the context of a web server before this RFC - at a glance I'd guess an unrecoverable fatal error would cause the worker to shut down. Would being in a different fiber and different C stack interfere with the shutdown process for fatal errors? (I guess the macros could be changed to make that switch to the main fiber if needed to fix that) Thanks, -Tyson Andre -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php