wfShellExec: Work around PHP 5.3 stream_select() issue
authorKevin Israel <pleasestand@live.com>
Wed, 30 Oct 2013 01:46:27 +0000 (21:46 -0400)
committerKevin Israel <pleasestand@live.com>
Wed, 30 Oct 2013 01:56:38 +0000 (21:56 -0400)
Follows-up e53af95c9301ca092ffa1f7de022beb24d60ea52.

Bug: 56360
Change-Id: I66f2dc8a2f43236799c23f6e25bbbd0a440f4283

includes/GlobalFunctions.php

index 7547d74..1ec7ba9 100644 (file)
@@ -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
+       // <https://bugs.php.net/bug.php?id=53427>.
+       $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] );