Closed FGIKCM closed 5 years ago
Hey there, the expected result you list won't exactly be displayed like that because the parent doesn't forward the STDOUT
from the client to it's own STDOUT
so CHILD:
echo's shouldn't be visible. Also assuming you use composers autoloading you shouldn't have to include the classes your self, as discussed here, composer will take care of that. I'll throw a gist together later today for this example and fix any issues coming up for you.
I use Eclipse as IDE, and launch the script as a "PHP client application": this echoes every processes output in it's console, so I catch everything (parent & child), it's pretty handy. And I agree for Composer, I fixed it in my project. It is just a dirty way to give you a working example :)
I just forgot to say that I develop on a Windows machine. But I just tested on a Debian, the result is the same: I don't have message sent. And the client output are hidden as you said. I even disabled them to be sure they won't interfere with the process, with no luck.
Well if Eclipse starts both processes that would example as the parent is supposed to start the child because it passes information to the child how to connect back to the parent for communication. If eclipse starts both it has no way to knowing where to connect to
After some heavy debug, it looks like that:
(When adding debug code in /vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php
, I see that I have no listener for 'message' event)
But I asked to register for it:
Flexible::createFromClass(ProcessJob::class, $this->loop, $options)
->then(
function (PoolInterface $pool) {
$pool->on('message', function (Payload $payload) {
echo "PARENT: message\n";
var_dump($payload);
});
);
Must I really use $pool
variable? Or must I use some Messenger object or something like that?
EDIT More info:
Flexible
objectWyriHaximus\React\ChildProcess\Messenger\Messenger
.That is the way you listen for messages. But are you sure the client starts the child and not Eclipse?
Yes, I tried in command line too, and the behavior is the same.
To debug, I wrote events on disk, and saw that messages are really sent from child to parent. But as I said, the $pool
(in fact: the Trait associated to the $pool
) has no listeners associated to the message
event. So the on(message) is not triggered on the parent side.
By the way, I am on PHP 7.3. I don't now if it makes any difference, but who knows
PHP version shouldn't affect this. Would have to look into it but it could be that the pool isn't forwarding the messages coming in from the messenger :zipper_mouth_face:
Any news on this issue? (I didn't deploy my project, waiting nights and days in front of my computer, hopping you will find the solution :D)
I tried to investigate the code by myself, but my skills are not sufficient to set up the message forwarding from the pool :'(
Hey this totally slipped my mind, will have a look at it during my commute home today. As I understand it correctly you want to send something from a child process in the pool back to the parent? Does RPC fit your requirements instead?
Yes, that's it. As the child takes some time to finish, I wanted to send back some messages at the end of each step (instead of sending the whole log at the end in the Payload)
Ok found the missing links and working on a solution
Related PR is up, once that one is merged and tagged I'll open the one for this repo: https://github.com/WyriHaximus/reactphp-child-process-messenger/pull/35
Great, thanks!!
1.6.0
has been released. Can you confirm for me that it works for you?
Yes! It works like a charm 👌 Thanks a lot!
Awesome! Glad to hear that
On my case, messages are not sent from child to parent. As if they were ignored, they are not sent, even at the end, when the connection close.
I understand that if my code is blocking, the message can't be send immediately, and must wait for $loop to do an iteration. But it should send the message-s, at least at the end, before shutting down. (I think it is the case in your code. So I must miss something stupid :-/ )
For example, this does not trigger a message interception on my parent:
On my parent, I intercept messages like this:
Am I missing something?
Here is the full example I use for my tests.
go.php (launcher)
ping.php (the parent)
pong.php (the child)
Result:
For this example, I hacked your
child-process.php
(booo) to loadpong.php
: