r/PHPhelp • • 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

10 comments sorted by

View all comments

Show parent comment

2

u/Tefkal1on Jul 30 '25

Thank you, yes, you're right, but there are some nuances.

A PHP class can only check the time inside a single thread.

The C extension can actually run an additional native thread (or timer) that monitors the timeout regardless of the execution of the PHP code.

This makes it possible to externally interrupt execution (for example, by setting a flag that will be checked inside a loop or wrapper), even if a heavy operation is underway inside the callback. Saving resources and speed.

Plus, this is not the final version of the extension, I decided to find out if it really would make sense to expand this solution further.

2

u/cursingcucumber Jul 31 '25

Sure you can set the boolean value.. but that does not have any immediate effect. As you say yourself, you will need to check the value in the loop yourself.

The only difference there is the value being there already in C vs "calculated" in PHP and therefore the C solution being quicker. Worth the hassle of an extension? Eh.. maybe.