@@ -398,6 +398,7 @@ public function execute()
398
398
stream_set_blocking ($ pipes [2 ], false );
399
399
if ($ hasInput ) {
400
400
$ writtenBytes = 0 ;
401
+ $ isInputOpen = true ;
401
402
stream_set_blocking ($ pipes [0 ], false );
402
403
if ($ isInputStream ) {
403
404
stream_set_blocking ($ this ->_stdIn , false );
@@ -408,10 +409,10 @@ public function execute()
408
409
// a loop if the process is still running. We also need to
409
410
// ensure that all the pipes are written/read alternately
410
411
// until there's nothing left to write/read.
411
- $ running = true ;
412
- while ($ running ) {
412
+ $ isRunning = true ;
413
+ while ($ isRunning ) {
413
414
$ status = proc_get_status ($ process );
414
- $ running = $ status ['running ' ];
415
+ $ isRunning = $ status ['running ' ];
415
416
416
417
// We first write to stdIn if we have an input. For big
417
418
// inputs it will only write until the input buffer of
@@ -421,10 +422,11 @@ public function execute()
421
422
//
422
423
// After everything is written it's safe to close the
423
424
// input pipe.
424
- if ($ hasInput && $ running ) {
425
+ if ($ isRunning && $ hasInput && $ isInputOpen ) {
425
426
if ($ isInputStream ) {
426
427
$ written = stream_copy_to_stream ($ this ->_stdIn , $ pipes [0 ], 16 * 1024 , $ writtenBytes );
427
428
if ($ written === false || $ written === 0 ) {
429
+ $ isInputOpen = false ;
428
430
fclose ($ pipes [0 ]);
429
431
} else {
430
432
$ writtenBytes += $ written ;
@@ -433,14 +435,15 @@ public function execute()
433
435
if ($ writtenBytes < strlen ($ this ->_stdIn )) {
434
436
$ writtenBytes += fwrite ($ pipes [0 ], substr ($ this ->_stdIn , $ writtenBytes ));
435
437
} else {
438
+ $ isInputOpen = false ;
436
439
fclose ($ pipes [0 ]);
437
440
}
438
441
}
439
442
}
440
443
441
444
// Read out the output buffers because if they are full
442
445
// the command may block execution. We do this even if
443
- // $running is `false`, because there could be output
446
+ // $isRunning is `false`, because there could be output
444
447
// left in the buffers.
445
448
//
446
449
// The latter is only an assumption and needs to be
@@ -454,7 +457,7 @@ public function execute()
454
457
$ this ->_stdErr .= $ err ;
455
458
}
456
459
457
- if (!$ running ) {
460
+ if (!$ isRunning ) {
458
461
$ this ->_exitCode = $ status ['exitcode ' ];
459
462
fclose ($ pipes [1 ]);
460
463
fclose ($ pipes [2 ]);
0 commit comments