r/PHPhelp • u/Tefkal1on • Jul 29 '25
php_context
https://github.com/Pashgunt/php_context
I present my implementation of Context implemented as an extension for php in C, if you think it might be useful or have any suggestions, please rate
5
Upvotes
3
u/99thLuftballon Jul 29 '25
I feel like you could've given it a better name. Context has so many meanings in programming, but it doesn't say "time out stopwatch" to me.
2
u/MateusAzevedo Jul 29 '25
Not sure if I ever needed something like this, but looks like an interesting feature.
Consider making it compatible with PIE, the new extension installer intended to replace PECL.
2
u/cursingcucumber Jul 29 '25
I believe this pattern is called collaborative cancellation.
As far as I understand from the readme, it does not stop/kill the execution after the timeout automatically. Instead you need to handle the cancellation yourself.
Not really sure why was chosen to do this as an extension as this can quite easily be done in a few lines of PHP I think? Unless there's something I missed.
3
u/Ahabraham Jul 30 '25
You missed a lot of important things about the design of Context in golang. Notably: Creating children contexts, different forms of context lifespans (such as cancellable ones), signal propagation through children, and embedding objects in context. I think the reality is though, you don’t need a golang style Context in PHP because you don’t have golang style concurrency to contend with. It’s about request scoped variable management and cancellation of work across threads, both of which PHP has solved in different mechanisms that are more natively aligned with the design of PHP
2
u/PetahNZ Jul 29 '25
Why is this an extension? Can't this be done in plain PHP?