Open factormaarten opened 6 years ago
I too would be interested in the solution here
Could you replace the then
's with done
, and post the errors here?
I've tried that, but it's not giving any errors unfortunately
That is weird, there should always be something. I'll run your code tonight and see if it works on my end
With some minor edits it works:
$loop = EventLoopFactory::create();
CpuCoreCountFlexible::createFromClass(PhalconSQL::class, $loop)->done(function (PoolInterface $pool) {
echo 'tack' . PHP_EOL;
$pool->rpc(
MessagesFactory::rpc('executeQuery')
)->done(function (Payload $result) use ($pool) {
echo $result['response'] . PHP_EOL;
$pool->terminate();
});
echo 'tock' . PHP_EOL;
});
$loop->run();
Thanks for the response. This is what's happening:
I start the loop, it echo's tack, it echo's tock and after that it keeps waiting for $result['response']
use React\EventLoop\LoopInterface;
use WyriHaximus\React\ChildProcess\Messenger\ChildInterface;
use WyriHaximus\React\ChildProcess\Messenger\Messenger;
use WyriHaximus\React\ChildProcess\Messenger\Messages\Payload;
use function React\Promise\resolve;
final class ReturnChild implements ChildInterface
{
public static function create(Messenger $messenger, LoopInterface $loop)
{
$messenger->registerRpc('executeQuery', function (Payload $payload) {
return resolve([
'response' => 'works'
]);
});
}
}
I don't see anything going wrong here. As I see it the promise should resolve.
With those edits above it works for me earlier this week:
I'll set up a repo somewhere this weekend that has your code working
Hey @mpjraaij just set up a repository at https://github.com/WyriHaximus/shiny-octo-adventure run composer install
and then php run.php
and it (should) work. If it doesn't could you run strace php run.php > strace.txt 2>&1
and email strace.txt
to the email address listed on my profile?
Thanks a lot! I'll go over it this week and see if it works :) if not I'll send you an email.
:+1:
Hi @WyriHaximus I tried to get the flexible pool to work by using a custom class. But every time I try the return-class example with a 100% identical copy of the ReturnChild class delivered by the messaging package, I get no resolve at all. (The only difference would be the name)
Also tried this on different environments: Debian, php7.0-7.4 OSX, php7.0-7.4 7.0 even breaks the whole project, which was kinda obvious.
eventloopserver.php
Flexible::createFromClass(LoopChildProcess::class, $loop)
->then(function (PoolInterface $pool) {
echo 'tack', PHP_EOL;
for ($i = 0; $i < 100; $i++) {
//echo $i, PHP_EOL;
$pool->rpc(
MessagesFactory::rpc(
'return',
[
'i' => $i,
'time' => time(),
//'string' => str_pad('0', 1024 * 1024 * 5)
'string' => str_pad('0', 5)
]
)
)->then(function (Payload $payload) use ($pool) {
echo $payload['i'], PHP_EOL;
echo $payload['time'], PHP_EOL;
if ($payload['i'] == 99) {
$pool->terminate();
}
var_export($pool->info());
});
}
echo 'tock', PHP_EOL;
});
$loop->run();
I also replaced the then()
's with done()
's, no error and actually just waiting for the promise resolve.
The LoopChildProcess has no namespace and is required the eventloopserver.php.
But the weird thing is everything works perfectly fine if I use:
Flexible::createFromClass('WyriHaximus\React\ChildProcess\Messenger\ReturnChild', $loop)
Anything I'm misunderstanding about the usage? Thanks for the help in advance.
hey @cluigDE silly question but is LoopChildProcess
autoloaded?
No, the file containing the class was just included in the file eventloopserver.php
Didn't thought of autoloading the class in composer. Will do that. Thanks.
Hi Cees-Jan,
I'm trying to get the pool running, but something isn't adding up for me. This is the class I'm calling:
Here's how I'm calling the rpc:
What should I change to make it all resolve?
Thanks so much! Maarten