(Bug 37957) Replace php_sapi_name() with PHP_SAPI
authorOri Livneh <ori@wikimedia.org>
Mon, 4 Feb 2013 03:01:17 +0000 (19:01 -0800)
committerOri Livneh <ori@wikimedia.org>
Mon, 4 Feb 2013 20:50:45 +0000 (12:50 -0800)
The PHP_SAPI constant has been available since PHP 4.2.0. It's more
concise to use the constant and has less overhead than a function call.

Furthermore, PHP_SAPI rhymes with "happy", whereas "php_sapi_name"
rhymes with "lame". QED, etc.

Change-Id: Ie8c121cb8fcef50536af8d3f66723b458f0bf9af

21 files changed:
includes/DefaultSettings.php
includes/ForkController.php
includes/GlobalFunctions.php
includes/api/ApiQuerySiteinfo.php
includes/filebackend/SwiftFileBackend.php
includes/normal/RandomTest.php
includes/normal/Utf8CaseGenerate.php
includes/normal/Utf8Test.php
includes/normal/UtfNormalBench.php
includes/normal/UtfNormalGenerate.php
includes/normal/UtfNormalMemStress.php
includes/normal/UtfNormalTest.php
includes/normal/UtfNormalTest2.php
includes/profiler/ProfilerSimpleText.php
includes/profiler/ProfilerSimpleTrace.php
includes/specials/SpecialVersion.php
maintenance/Maintenance.php
maintenance/dev/includes/router.php
maintenance/locking/LockServerDaemon.php
maintenance/mwdocgen.php
maintenance/proxy_check.php

index ca6505c..68c4542 100644 (file)
@@ -123,9 +123,9 @@ $wgScriptPath       = '/wiki';
  * redirect loops when "pretty URLs" are used.
  */
 $wgUsePathInfo =
-       ( strpos( php_sapi_name(), 'cgi' ) === false ) &&
-       ( strpos( php_sapi_name(), 'apache2filter' ) === false ) &&
-       ( strpos( php_sapi_name(), 'isapi' ) === false );
+       ( strpos( PHP_SAPI, 'cgi' ) === false ) &&
+       ( strpos( PHP_SAPI, 'apache2filter' ) === false ) &&
+       ( strpos( PHP_SAPI, 'isapi' ) === false );
 
 /**
  * The extension to append to script names by default. This can either be .php
index 2a05411..89ad955 100644 (file)
@@ -53,7 +53,7 @@ class ForkController {
        const RESTART_ON_ERROR = 1;
 
        public function __construct( $numProcs, $flags = 0 ) {
-               if ( php_sapi_name() != 'cli' ) {
+               if ( PHP_SAPI != 'cli' ) {
                        throw new MWException( "ForkController cannot be used from the web." );
                }
                $this->procsToStart = $numProcs;
index 1ff9ac7..c57018e 100644 (file)
@@ -2681,8 +2681,7 @@ function wfDl( $extension, $fileName = null ) {
        }
 
        $canDl = false;
-       $sapi = php_sapi_name();
-       if( $sapi == 'cli' || $sapi == 'cgi' || $sapi == 'embed' ) {
+       if( PHP_SAPI == 'cli' || PHP_SAPI == 'cgi' || PHP_SAPI == 'embed' ) {
                $canDl = ( function_exists( 'dl' ) && is_callable( 'dl' )
                && wfIniGetBool( 'enable_dl' ) && !wfIniGetBool( 'safe_mode' ) );
        }
index 04897e8..3b4220c 100644 (file)
@@ -120,7 +120,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
                $data['sitename'] = $GLOBALS['wgSitename'];
                $data['generator'] = "MediaWiki {$GLOBALS['wgVersion']}";
                $data['phpversion'] = phpversion();
-               $data['phpsapi'] = php_sapi_name();
+               $data['phpsapi'] = PHP_SAPI;
                $data['dbtype'] = $GLOBALS['wgDBtype'];
                $data['dbversion'] = $this->getDB()->getServerVersion();
 
index 3c097a1..d825d04 100644 (file)
@@ -148,7 +148,7 @@ class SwiftFileBackend extends FileBackendStore {
                $this->connContainerCache = new ProcessCacheLRU( 300 );
                // Cache auth token information to avoid RTTs
                if ( !empty( $config['cacheAuthInfo'] ) ) {
-                       if ( php_sapi_name() === 'cli' ) {
+                       if ( PHP_SAPI === 'cli' ) {
                                $this->srvCache = wfGetMainCache(); // preferrably memcached
                        } else {
                                try { // look for APC, XCache, WinCache, ect...
index 23471e9..9dc1c86 100644 (file)
@@ -26,7 +26,7 @@
  * @ingroup UtfNormal
  */
 
-if( php_sapi_name() != 'cli' ) {
+if( PHP_SAPI != 'cli' ) {
        die( "Run me from the command line please.\n" );
 }
 
index d9deb3c..eaa2304 100644 (file)
@@ -25,7 +25,7 @@
  * @ingroup UtfNormal
  */
 
-if( php_sapi_name() != 'cli' ) {
+if( PHP_SAPI != 'cli' ) {
        die( "Run me from the command line please.\n" );
 }
 
index 6eae6e7..904a27f 100644 (file)
@@ -34,7 +34,7 @@ mb_internal_encoding( "utf-8" );
 
 $verbose = false;
 #$verbose = true;
-if( php_sapi_name() != 'cli' ) {
+if( PHP_SAPI != 'cli' ) {
        die( "Run me from the command line please.\n" );
 }
 
index 9a05b81..392ba2b 100644 (file)
@@ -34,7 +34,7 @@ require_once 'UtfNormal.php';
 
 define( 'BENCH_CYCLES', 5 );
 
-if( php_sapi_name() != 'cli' ) {
+if( PHP_SAPI != 'cli' ) {
        die( "Run me from the command line please.\n" );
 }
 
index 11d06d4..f392df5 100644 (file)
@@ -25,7 +25,7 @@
  * @ingroup UtfNormal
  */
 
-if( php_sapi_name() != 'cli' ) {
+if( PHP_SAPI != 'cli' ) {
        die( "Run me from the command line please.\n" );
 }
 
index 7162a8b..257e105 100644 (file)
@@ -38,7 +38,7 @@ define( 'BENCH_CYCLES', 1 );
 define( 'BIGSIZE', 1024 * 1024 * 10); // 10m
 ini_set('memory_limit', BIGSIZE + 120 * 1024 * 1024);
 
-if( php_sapi_name() != 'cli' ) {
+if( PHP_SAPI != 'cli' ) {
        die( "Run me from the command line please.\n" );
 }
 
index 5872ec3..22e6471 100644 (file)
@@ -54,7 +54,7 @@ require_once 'UtfNormalDefines.php';
 require_once 'UtfNormalUtil.php';
 require_once 'UtfNormal.php';
 
-if( php_sapi_name() != 'cli' ) {
+if( PHP_SAPI != 'cli' ) {
        die( "Run me from the command line please.\n" );
 }
 
index 691bfaa..f4a8379 100644 (file)
@@ -22,7 +22,7 @@
  * @ingroup UtfNormal
  */
 
-if( php_sapi_name() != 'cli' ) {
+if( PHP_SAPI != 'cli' ) {
        die( "Run me from the command line please.\n" );
 }
 
index 847e34f..37350bf 100644 (file)
@@ -50,7 +50,7 @@ class ProfilerSimpleText extends ProfilerSimple {
                                : 0; // profiling mismatch error?
                        uasort( $this->mCollated, array( 'self', 'sort' ) );
                        array_walk( $this->mCollated, array( 'self', 'format' ), $totalReal );
-                       if ( php_sapi_name() === 'cli' ) {
+                       if ( PHP_SAPI === 'cli' ) {
                                print "<!--\n".self::$out."\n-->\n";
                        } elseif ( $this->getContentType() === 'text/html' ) {
                                if ( $this->visible ) {
index f766a39..d44dfe1 100644 (file)
@@ -69,7 +69,7 @@ class ProfilerSimpleTrace extends ProfilerSimple {
        }
 
        function logData() {
-               if ( php_sapi_name() === 'cli' ) {
+               if ( PHP_SAPI === 'cli' ) {
                        print "<!-- \n {$this->trace} \n -->";
                } elseif ( $this->getContentType() === 'text/html' ) {
                        print "<!-- \n {$this->trace} \n -->";
index c87a6ff..b04f1ef 100644 (file)
@@ -148,7 +148,7 @@ class SpecialVersion extends SpecialPage {
                // wikimarkup can be used.
                $software = array();
                $software['[https://www.mediawiki.org/ MediaWiki]'] = self::getVersionLinked();
-               $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . php_sapi_name() . ")";
+               $software['[http://www.php.net/ PHP]'] = phpversion() . " (" . PHP_SAPI . ")";
                $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo();
 
                // Allow a hook to add/remove items.
index c320695..2a8b8e5 100644 (file)
@@ -342,7 +342,7 @@ abstract class Maintenance {
         */
        protected function error( $err, $die = 0 ) {
                $this->outputChanneled( false );
-               if ( php_sapi_name() == 'cli' ) {
+               if ( PHP_SAPI == 'cli' ) {
                        fwrite( STDERR, $err . "\n" );
                } else {
                        print $err;
index ac96f45..1d5070b 100644 (file)
@@ -21,7 +21,7 @@
  * @file
  */
 
-if ( php_sapi_name() != 'cli-server' ) {
+if ( PHP_SAPI != 'cli-server' ) {
        die( "This script can only be run by php's cli-server sapi." );
 }
 
index 0ba9bfe..01fbac7 100644 (file)
@@ -23,7 +23,7 @@
  * @ingroup LockManager Maintenance
  */
 
-if ( php_sapi_name() !== 'cli' ) {
+if ( PHP_SAPI !== 'cli' ) {
        die( "This is not a valid entry point.\n" );
 }
 error_reporting( E_ALL );
index 6e01291..429e3b3 100644 (file)
@@ -43,7 +43,7 @@
 # Variables / Configuration
 #
 
-if ( php_sapi_name() != 'cli' ) {
+if ( PHP_SAPI != 'cli' ) {
        echo 'Run "' . __FILE__ . '" from the command line.';
        die( -1 );
 }
index 10892c4..2ccf703 100644 (file)
@@ -21,7 +21,7 @@
  * @ingroup Maintenance
  */
 
-if( php_sapi_name() != 'cli' ) {
+if( PHP_SAPI != 'cli' ) {
        die( 1 );
 }