This is a quick demo / proof of concept combining promises (React/Promise
) with serializing (using Opis/Closure
) - allowing us to create promises that resolve in a later PHP thread.
To make this work correctly, after composer install
you need to maunually apply reactphp/promise#179 to vendor/react/promise/src/Promise.php
.
Basic premise is a greeter class. When someone arrives we greet them, assign them an id & create a promise can be resolved when they leave - farewelling them by name.
For this to work the promise must not only successfully serialise its resolve closure, it must also retain/restore the $this
instance being called within the then
callback when the promise is resolved. If this fails it will not know the name to farewell.
- Ensure
guests
is writable. - Run
index.php
. This will create a promise & give you instructions on resolving the promise. - Run the command provided in step 2 - something like
php resolve.php <id>