@@ -261,7 +261,7 @@ public function start($callback = null)
261
261
stream_set_blocking ($ pipe , false );
262
262
}
263
263
264
- $ this ->writePipes (false );
264
+ $ this ->writePipes ();
265
265
$ this ->updateStatus (false );
266
266
$ this ->checkTimeout ();
267
267
}
@@ -313,9 +313,9 @@ public function wait($callback = null)
313
313
if (null !== $ callback ) {
314
314
$ this ->callback = $ this ->buildCallback ($ callback );
315
315
}
316
- while ($ this ->processInformation ['running ' ]) {
317
- $ this ->updateStatus (true );
316
+ while ($ this ->pipes || (defined ('PHP_WINDOWS_VERSION_BUILD ' ) && $ this ->fileHandles )) {
318
317
$ this ->checkTimeout ();
318
+ $ this ->readPipes (true );
319
319
}
320
320
$ this ->updateStatus (false );
321
321
if ($ this ->processInformation ['signaled ' ]) {
@@ -1162,23 +1162,7 @@ private function readPipes($blocking)
1162
1162
return ;
1163
1163
}
1164
1164
1165
- foreach ($ r as $ pipe ) {
1166
- $ type = array_search ($ pipe , $ this ->pipes );
1167
- $ data = fread ($ pipe , 8192 );
1168
-
1169
- if (strlen ($ data ) > 0 ) {
1170
- // last exit code is output and caught to work around --enable-sigchild
1171
- if (3 == $ type ) {
1172
- $ this ->fallbackExitcode = (int ) $ data ;
1173
- } else {
1174
- call_user_func ($ this ->callback , $ type == 1 ? self ::OUT : self ::ERR , $ data );
1175
- }
1176
- }
1177
- if (false === $ data || feof ($ pipe )) {
1178
- fclose ($ pipe );
1179
- unset($ this ->pipes [$ type ]);
1180
- }
1181
- }
1165
+ $ this ->processReadPipes ($ r );
1182
1166
}
1183
1167
}
1184
1168
@@ -1187,7 +1171,7 @@ private function readPipes($blocking)
1187
1171
*
1188
1172
* @param Boolean $blocking Whether to use blocking calls or not.
1189
1173
*/
1190
- private function writePipes ($ blocking )
1174
+ private function writePipes ()
1191
1175
{
1192
1176
if ($ this ->tty ) {
1193
1177
$ this ->status = self ::STATUS_TERMINATED ;
@@ -1208,7 +1192,11 @@ private function writePipes($blocking)
1208
1192
$ stdinOffset = 0 ;
1209
1193
1210
1194
while ($ writePipes ) {
1211
- $ r = array ();
1195
+ if (defined ('PHP_WINDOWS_VERSION_BUILD ' )) {
1196
+ $ this ->processFileHandles ();
1197
+ }
1198
+
1199
+ $ r = $ this ->pipes ;
1212
1200
$ w = $ writePipes ;
1213
1201
$ e = null ;
1214
1202
@@ -1235,6 +1223,34 @@ private function writePipes($blocking)
1235
1223
$ writePipes = null ;
1236
1224
}
1237
1225
}
1226
+
1227
+ $ this ->processReadPipes ($ r );
1228
+ }
1229
+ }
1230
+
1231
+ /**
1232
+ * Processes read pipes, executes callback on it.
1233
+ *
1234
+ * @param array $pipes
1235
+ */
1236
+ private function processReadPipes (array $ pipes )
1237
+ {
1238
+ foreach ($ pipes as $ pipe ) {
1239
+ $ type = array_search ($ pipe , $ this ->pipes );
1240
+ $ data = fread ($ pipe , 8192 );
1241
+
1242
+ if (strlen ($ data ) > 0 ) {
1243
+ // last exit code is output and caught to work around --enable-sigchild
1244
+ if (3 == $ type ) {
1245
+ $ this ->fallbackExitcode = (int ) $ data ;
1246
+ } else {
1247
+ call_user_func ($ this ->callback , $ type == 1 ? self ::OUT : self ::ERR , $ data );
1248
+ }
1249
+ }
1250
+ if (false === $ data || feof ($ pipe )) {
1251
+ fclose ($ pipe );
1252
+ unset($ this ->pipes [$ type ]);
1253
+ }
1238
1254
}
1239
1255
}
1240
1256
}
0 commit comments