@@ -287,7 +287,7 @@ public function start($callback = null)
287
287
stream_set_blocking ($ pipe , false );
288
288
}
289
289
290
- $ this ->writePipes (false );
290
+ $ this ->writePipes ();
291
291
$ this ->updateStatus (false );
292
292
$ this ->checkTimeout ();
293
293
}
@@ -339,9 +339,9 @@ public function wait($callback = null)
339
339
if (null !== $ callback ) {
340
340
$ this ->callback = $ this ->buildCallback ($ callback );
341
341
}
342
- while ($ this ->processInformation ['running ' ]) {
343
- $ this ->updateStatus (true );
342
+ while ($ this ->pipes || (defined ('PHP_WINDOWS_VERSION_BUILD ' ) && $ this ->fileHandles )) {
344
343
$ this ->checkTimeout ();
344
+ $ this ->readPipes (true );
345
345
}
346
346
$ this ->updateStatus (false );
347
347
if ($ this ->processInformation ['signaled ' ]) {
@@ -1069,23 +1069,7 @@ private function readPipes($blocking)
1069
1069
return ;
1070
1070
}
1071
1071
1072
- foreach ($ r as $ pipe ) {
1073
- $ type = array_search ($ pipe , $ this ->pipes );
1074
- $ data = fread ($ pipe , 8192 );
1075
-
1076
- if (strlen ($ data ) > 0 ) {
1077
- // last exit code is output and caught to work around --enable-sigchild
1078
- if (3 == $ type ) {
1079
- $ this ->fallbackExitcode = (int ) $ data ;
1080
- } else {
1081
- call_user_func ($ this ->callback , $ type == 1 ? self ::OUT : self ::ERR , $ data );
1082
- }
1083
- }
1084
- if (false === $ data || feof ($ pipe )) {
1085
- fclose ($ pipe );
1086
- unset($ this ->pipes [$ type ]);
1087
- }
1088
- }
1072
+ $ this ->processReadPipes ($ r );
1089
1073
}
1090
1074
}
1091
1075
@@ -1094,7 +1078,7 @@ private function readPipes($blocking)
1094
1078
*
1095
1079
* @param Boolean $blocking Whether to use blocking calls or not.
1096
1080
*/
1097
- private function writePipes ($ blocking )
1081
+ private function writePipes ()
1098
1082
{
1099
1083
if (null === $ this ->stdin ) {
1100
1084
fclose ($ this ->pipes [0 ]);
@@ -1109,7 +1093,11 @@ private function writePipes($blocking)
1109
1093
$ stdinOffset = 0 ;
1110
1094
1111
1095
while ($ writePipes ) {
1112
- $ r = array ();
1096
+ if (defined ('PHP_WINDOWS_VERSION_BUILD ' )) {
1097
+ $ this ->processFileHandles ();
1098
+ }
1099
+
1100
+ $ r = $ this ->pipes ;
1113
1101
$ w = $ writePipes ;
1114
1102
$ e = null ;
1115
1103
@@ -1136,6 +1124,34 @@ private function writePipes($blocking)
1136
1124
$ writePipes = null ;
1137
1125
}
1138
1126
}
1127
+
1128
+ $ this ->processReadPipes ($ r );
1129
+ }
1130
+ }
1131
+
1132
+ /**
1133
+ * Processes read pipes, executes callback on it.
1134
+ *
1135
+ * @param array $pipes
1136
+ */
1137
+ private function processReadPipes (array $ pipes )
1138
+ {
1139
+ foreach ($ pipes as $ pipe ) {
1140
+ $ type = array_search ($ pipe , $ this ->pipes );
1141
+ $ data = fread ($ pipe , 8192 );
1142
+
1143
+ if (strlen ($ data ) > 0 ) {
1144
+ // last exit code is output and caught to work around --enable-sigchild
1145
+ if (3 == $ type ) {
1146
+ $ this ->fallbackExitcode = (int ) $ data ;
1147
+ } else {
1148
+ call_user_func ($ this ->callback , $ type == 1 ? self ::OUT : self ::ERR , $ data );
1149
+ }
1150
+ }
1151
+ if (false === $ data || feof ($ pipe )) {
1152
+ fclose ($ pipe );
1153
+ unset($ this ->pipes [$ type ]);
1154
+ }
1139
1155
}
1140
1156
}
1141
1157
}
0 commit comments