From 8bd6f698ccb990c9a9d37f495b8b5b7620832018 Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Tue, 29 Oct 2013 21:46:27 -0400 Subject: [PATCH] wfShellExec: Work around PHP 5.3 stream_select() issue Follows-up e53af95c9301ca092ffa1f7de022beb24d60ea52. Bug: 56360 Change-Id: I66f2dc8a2f43236799c23f6e25bbbd0a440f4283 --- includes/GlobalFunctions.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 7547d74194..1ec7ba9fe8 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2837,6 +2837,14 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(), $limits = array $eintr = defined( 'SOCKET_EINTR' ) ? SOCKET_EINTR : 4; $eintrMessage = "stream_select(): unable to select [$eintr]"; + // Build a table mapping resource IDs to pipe FDs to work around a + // PHP 5.3 issue in which stream_select() does not preserve array keys + // . + $fds = array(); + foreach ( $pipes as $fd => $pipe ) { + $fds[(int)$pipe] = $fd; + } + while ( true ) { $status = proc_get_status( $proc ); if ( !$status['running'] ) { @@ -2858,8 +2866,9 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(), $limits = array break; } } - foreach ( $readyPipes as $fd => $pipe ) { + foreach ( $readyPipes as $pipe ) { $block = fread( $pipe, 65536 ); + $fd = $fds[(int)$pipe]; if ( $block === '' ) { // End of file fclose( $pipes[$fd] ); -- 2.20.1