-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
immediately close the child handle for a pipe after retrieving all co… #27
Conversation
I'm very averse to changing this. Whenever we touch this we see new reports about things breaking or blocked executions, see #20. I've already reverted a couple of fixes as each of them introduced new problems. So I don't want to change this before we can't clearly identify the issue in #20 and have test cases for it. |
@schmunk42 Have you also tried the proposed fix in #20?
Would this also fix your problem? |
I remember now :) I played around with I think it would be nice to have a parameter for A parameter for switching the order of getting STDOUT and STDERR might be a bit overkill, but could also help - I am not sure here. The idea behind my proposed change was just to close the stream, when finished reading, instead of having an open file handle for the first stream, when reading the second one. We were seeing this problem in our logs: https://serverfault.com/questions/839135/nginx-php-fpm-child-exited-with-code-0 |
Maybe this could also be related to STDIN? Please see https://bugs.php.net/bug.php?id=73342 So shellcommand's
|
@schmunk42 Not sure if you're still using this library but maybe you could help testing PR #41? I've now completely refactored the execution with |
I'll try to take a look. My usage was mainly with this lib: https://github.com/omauger/docker-compose-php Basically I wanted to immediately see the output from |
Right, I remember now. Honestly I think that we can't support immediate output. If you check the code, using non-blocking streams is already complex enough. I can't think of an easy way how you'd implement that real-time output feature. So for that use case you'd need another library - or brew your own solution for that specific use case. I doubt that there's a simple generic solution. |
@schmunk42 Closing this for now as the original issue should be solved with 1.5.0. Regarding immediate output: I was thinking about a complete rewrite of the library with a cleaner interface. In theory I think immediate output would be possible - but at the cost that the code you need to write always becomes ugly. Basically you'd need a loop in your code, something like this: $command = new Command('sleep 20');
$command->runAsync();
while ($command->isRunning()) {
echo $command->getOutput();
} But to be on the safe side, that's not enough. You'd have to copy the logic to alternately check the stdin/stdout streams in your code: php-shellcommand/src/Command.php Lines 408 to 470 in e7bdc8a
You always need to check how much of the input/output you've already sent/received. The library could buffer this internally to make things a little easier (e.g. with php://temp or php://memory). But to be honest I feel like there's too many scenarios where things can go horribly wrong. Maintaning could soon become a nightmare. So I'd say: If you need this, it's really better to build or own logic with |
…ntent
prevents issues which can arise from getting content of blocking/non-blocking streams while running in FPM.