aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKunal Mehta <legoktm@member.fsf.org>2018-01-02 22:51:44 -0800
committerKunal Mehta <legoktm@member.fsf.org>2018-01-03 23:00:37 -0800
commit251a0b97e5bb8711bac1784e90f9b7d61377e7da (patch)
tree560293cc6766ce2ff0a003d3aae3865b2a8bb229
parent2e248f0bb20cbdf7738a6d44a843eb546c3bbf23 (diff)
downloadmediawikicore-251a0b97e5bb8711bac1784e90f9b7d61377e7da.tar.gz
mediawikicore-251a0b97e5bb8711bac1784e90f9b7d61377e7da.zip
Treat phpdbg as run from the command line when checking PHP_SAPI
phpdbg is a gdb-style debugger for PHP that is run from the command line. However, it has a different PHP_SAPI value, so it was impossible to run maintenance scripts with it (until now). To avoid having to check both PHP_SAPI values in a bunch of places, introduce wfIsCLI() to easily check whether running from the command-line or not. We're (CI team) interested in generating code coverage with phpdbg instead of xdebug, hence this patch. Bug: T184043 Change-Id: Id1f994ca146d7858cd8bb6ab6cdbb7718ff524fb
-rw-r--r--includes/ForkController.php2
-rw-r--r--includes/GlobalFunctions.php12
-rw-r--r--includes/debug/logger/monolog/WikiProcessor.php2
-rw-r--r--includes/exception/MWExceptionHandler.php2
-rw-r--r--includes/libs/lockmanager/LockManager.php2
-rw-r--r--includes/libs/rdbms/database/Database.php4
-rw-r--r--includes/libs/rdbms/loadbalancer/LoadBalancer.php4
-rw-r--r--includes/profiler/Profiler.php3
-rw-r--r--includes/profiler/output/ProfilerOutputText.php2
-rw-r--r--includes/utils/UIDGenerator.php2
-rw-r--r--maintenance/Maintenance.php5
-rw-r--r--maintenance/generateLocalAutoload.php2
-rw-r--r--maintenance/mwdoc-filter.php2
13 files changed, 30 insertions, 14 deletions
diff --git a/includes/ForkController.php b/includes/ForkController.php
index 2dde17be0803..cc16964e1fdd 100644
--- a/includes/ForkController.php
+++ b/includes/ForkController.php
@@ -54,7 +54,7 @@ class ForkController {
const RESTART_ON_ERROR = 1;
public function __construct( $numProcs, $flags = 0 ) {
- if ( PHP_SAPI != 'cli' ) {
+ if ( !wfIsCLI() ) {
throw new MWException( "ForkController cannot be used from the web." );
}
$this->procsToStart = $numProcs;
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index 523a0f93a69e..7b770900fac0 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -2089,6 +2089,16 @@ function wfIsHHVM() {
}
/**
+ * Check if we are running from the commandline
+ *
+ * @since 1.31
+ * @return bool
+ */
+function wfIsCLI() {
+ return PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg';
+}
+
+/**
* Tries to get the system directory for temporary files. First
* $wgTmpDirectory is checked, and then the TMPDIR, TMP, and TEMP
* environment variables are then checked in sequence, then
@@ -3031,7 +3041,7 @@ function wfWaitForSlaves(
$ifWritesSince = null, $wiki = false, $cluster = false, $timeout = null
) {
if ( $timeout === null ) {
- $timeout = ( PHP_SAPI === 'cli' ) ? 86400 : 10;
+ $timeout = wfIsCLI() ? 86400 : 10;
}
if ( $cluster === '*' ) {
diff --git a/includes/debug/logger/monolog/WikiProcessor.php b/includes/debug/logger/monolog/WikiProcessor.php
index e39a2c300a9a..db5b9bf6693c 100644
--- a/includes/debug/logger/monolog/WikiProcessor.php
+++ b/includes/debug/logger/monolog/WikiProcessor.php
@@ -39,7 +39,7 @@ class WikiProcessor {
$record['extra']['wiki'] = wfWikiID();
$record['extra']['mwversion'] = $wgVersion;
$record['extra']['reqId'] = \WebRequest::getRequestId();
- if ( PHP_SAPI === 'cli' && isset( $_SERVER['argv'] ) ) {
+ if ( wfIsCLI() && isset( $_SERVER['argv'] ) ) {
$record['extra']['cli_argv'] = implode( ' ', $_SERVER['argv'] );
}
return $record;
diff --git a/includes/exception/MWExceptionHandler.php b/includes/exception/MWExceptionHandler.php
index f3d61f0cddb2..d863a2bb583c 100644
--- a/includes/exception/MWExceptionHandler.php
+++ b/includes/exception/MWExceptionHandler.php
@@ -121,7 +121,7 @@ class MWExceptionHandler {
self::handleException( $e );
// Make sure we don't claim success on exit for CLI scripts (T177414)
- if ( PHP_SAPI === 'cli' ) {
+ if ( wfIsCLI() ) {
register_shutdown_function(
function () {
exit( 255 );
diff --git a/includes/libs/lockmanager/LockManager.php b/includes/libs/lockmanager/LockManager.php
index a6257bfda904..6b3cfb44ae77 100644
--- a/includes/libs/lockmanager/LockManager.php
+++ b/includes/libs/lockmanager/LockManager.php
@@ -83,7 +83,7 @@ abstract class LockManager {
$this->domain = isset( $config['domain'] ) ? $config['domain'] : 'global';
if ( isset( $config['lockTTL'] ) ) {
$this->lockTTL = max( 5, $config['lockTTL'] );
- } elseif ( PHP_SAPI === 'cli' ) {
+ } elseif ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
$this->lockTTL = 3600;
} else {
$met = ini_get( 'max_execution_time' ); // this is 0 in CLI mode
diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php
index 15e02ad0857e..0418dfc078f7 100644
--- a/includes/libs/rdbms/database/Database.php
+++ b/includes/libs/rdbms/database/Database.php
@@ -394,7 +394,9 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
$p['variables'] = isset( $p['variables'] ) ? $p['variables'] : [];
$p['tablePrefix'] = isset( $p['tablePrefix'] ) ? $p['tablePrefix'] : '';
$p['schema'] = isset( $p['schema'] ) ? $p['schema'] : '';
- $p['cliMode'] = isset( $p['cliMode'] ) ? $p['cliMode'] : ( PHP_SAPI === 'cli' );
+ $p['cliMode'] = isset( $p['cliMode'] )
+ ? $p['cliMode']
+ : ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' );
$p['agent'] = isset( $p['agent'] ) ? $p['agent'] : '';
if ( !isset( $p['connLogger'] ) ) {
$p['connLogger'] = new \Psr\Log\NullLogger();
diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
index 591e287e0aa0..9a7f7e190801 100644
--- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php
+++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
@@ -232,7 +232,9 @@ class LoadBalancer implements ILoadBalancer {
$this->host = isset( $params['hostname'] )
? $params['hostname']
: ( gethostname() ?: 'unknown' );
- $this->cliMode = isset( $params['cliMode'] ) ? $params['cliMode'] : PHP_SAPI === 'cli';
+ $this->cliMode = isset( $params['cliMode'] )
+ ? $params['cliMode']
+ : ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' );
$this->agent = isset( $params['agent'] ) ? $params['agent'] : '';
if ( isset( $params['chronologyProtector'] ) ) {
diff --git a/includes/profiler/Profiler.php b/includes/profiler/Profiler.php
index 4da7976d82f4..81449be1f670 100644
--- a/includes/profiler/Profiler.php
+++ b/includes/profiler/Profiler.php
@@ -74,7 +74,8 @@ abstract class Profiler {
}
$inSample = mt_rand( 0, $params['sampling'] - 1 ) === 0;
- if ( PHP_SAPI === 'cli' || !$inSample ) {
+ // wfIsCLI() is not available yet
+ if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' || !$inSample ) {
$params['class'] = 'ProfilerStub';
}
diff --git a/includes/profiler/output/ProfilerOutputText.php b/includes/profiler/output/ProfilerOutputText.php
index dc24f1810252..100304ffb2b7 100644
--- a/includes/profiler/output/ProfilerOutputText.php
+++ b/includes/profiler/output/ProfilerOutputText.php
@@ -59,7 +59,7 @@ class ProfilerOutputText extends ProfilerOutput {
);
$contentType = $this->collector->getContentType();
- if ( PHP_SAPI === 'cli' ) {
+ if ( wfIsCLI() ) {
print "<!--\n{$out}\n-->\n";
} elseif ( $contentType === 'text/html' ) {
$visible = isset( $this->params['visible'] ) ?
diff --git a/includes/utils/UIDGenerator.php b/includes/utils/UIDGenerator.php
index 736109b49a58..68ef57ae2495 100644
--- a/includes/utils/UIDGenerator.php
+++ b/includes/utils/UIDGenerator.php
@@ -367,7 +367,7 @@ class UIDGenerator {
// Use APC/eAccelerator/xcache if requested, available, and not in CLI mode;
// Counter values would not survive accross script instances in CLI mode.
$cache = null;
- if ( ( $flags & self::QUICK_VOLATILE ) && PHP_SAPI !== 'cli' ) {
+ if ( ( $flags & self::QUICK_VOLATILE ) && !wfIsCLI() ) {
$cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
}
if ( $cache ) {
diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php
index 07f547f48abc..68c51a8839ea 100644
--- a/maintenance/Maintenance.php
+++ b/maintenance/Maintenance.php
@@ -410,7 +410,7 @@ abstract class Maintenance {
$this->fatalError( $err, intval( $die ) );
}
$this->outputChanneled( false );
- if ( PHP_SAPI == 'cli' ) {
+ if ( PHP_SAPI == 'cli' || PHP_SAPI == 'phpdbg' ) {
fwrite( STDERR, $err . "\n" );
} else {
print $err;
@@ -672,7 +672,8 @@ abstract class Maintenance {
global $IP, $wgCommandLineMode, $wgRequestTime;
# Abort if called from a web server
- if ( PHP_SAPI !== 'cli' ) {
+ # wfIsCLI() is not available yet
+ if ( PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' ) {
$this->fatalError( 'This script must be run from the command line' );
}
diff --git a/maintenance/generateLocalAutoload.php b/maintenance/generateLocalAutoload.php
index bec11a0de1d5..189858c5af5d 100644
--- a/maintenance/generateLocalAutoload.php
+++ b/maintenance/generateLocalAutoload.php
@@ -1,6 +1,6 @@
<?php
-if ( PHP_SAPI != 'cli' ) {
+if ( PHP_SAPI != 'cli' && PHP_SAPI != 'phpdbg' ) {
die( "This script can only be run from the command line.\n" );
}
diff --git a/maintenance/mwdoc-filter.php b/maintenance/mwdoc-filter.php
index feaad12a60dd..89fc44bd6ec0 100644
--- a/maintenance/mwdoc-filter.php
+++ b/maintenance/mwdoc-filter.php
@@ -39,7 +39,7 @@
*/
// Warning: Converting this to a Maintenance script may reduce performance.
-if ( PHP_SAPI != 'cli' ) {
+if ( PHP_SAPI != 'cli' && PHP_SAPI != 'phpdbg' ) {
die( "This filter can only be run from the command line.\n" );
}