Various fixes to job running code in Wiki.php
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 21 Jan 2014 19:32:18 +0000 (11:32 -0800)
committerTim Starling <tstarling@wikimedia.org>
Wed, 29 Jan 2014 22:56:38 +0000 (22:56 +0000)
* Make it async on Windows
* Fixed possible "invalid filename" errors on Windows
* Redirect output to dev/null to avoid hanging PHP

bug: 60231
bug: 58719
Change-Id: If4e52b86fb3a1bff283dfba3dfac213367f47543

includes/Wiki.php

index 9a6e6b9..56d23b1 100644 (file)
@@ -637,12 +637,19 @@ class MediaWiki {
                }
 
                if ( !wfShellExecDisabled() && is_executable( $wgPhpCli ) ) {
-                       // Start a background process to run some of the jobs.
-                       // This will be asynchronous on *nix though not on Windows.
+                       // Start a background process to run some of the jobs
                        wfProfileIn( __METHOD__ . '-exec' );
                        $retVal = 1;
                        $cmd = wfShellWikiCmd( "$IP/maintenance/runJobs.php", array( '--maxjobs', $n ) );
-                       wfShellExec( "$cmd &", $retVal );
+                       $cmd .= " >" . wfGetNull() . " 2>&1"; // don't hang PHP on pipes
+                       if ( wfIsWindows() ) {
+                               // Using START makes this async and also works around a bug where using
+                               // wfShellExec() with a quoted script name causes a filename syntax error.
+                               $cmd = "START /B \"bg\" $cmd";
+                       } else {
+                               $cmd = "$cmd &";
+                       }
+                       wfShellExec( $cmd, $retVal );
                        wfProfileOut( __METHOD__ . '-exec' );
                } else {
                        try {