From 04b205956f69effdc6aa4673553b6634e9b81959 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 13 Nov 2004 03:54:54 +0000 Subject: [PATCH] Allow the user to select what kind of shared memory they want, in the installer --- config/index.php | 118 ++++++++++++++++++++++++++++++++++- includes/DefaultSettings.php | 2 +- 2 files changed, 118 insertions(+), 2 deletions(-) diff --git a/config/index.php b/config/index.php index 63ba307ede..ef570f763d 100644 --- a/config/index.php +++ b/config/index.php @@ -278,6 +278,14 @@ if( $conf->zlib ) { print "
  • No zlib support.
  • \n"; } +$conf->turck = function_exists( 'mmcache_get' ); +if ( $conf->turck ) { + print "
  • Turck MMCache installed
  • \n"; +} else { + print "
  • Turck MMCache not installed, " . + "can't use object caching functions
  • \n"; +} + $conf->ImageMagick = false; $imcheck = array( "/usr/bin", "/usr/local/bin", "/sw/bin", "/opt/local/bin" ); foreach( $imcheck as $dir ) { @@ -365,6 +373,24 @@ if( $conf->License == "gfdl" ) { $conf->RightsIcon = importRequest( "RightsIcon", "" ); } +$conf->Shm = importRequest( "Shm", "none" ); +$conf->MCServers = importRequest( "MCServers" ); + +/* Test memcached servers */ + +if ( $conf->Shm == 'memcached' && $conf->MCServers ) { + $conf->MCServerArray = array_map( 'trim', explode( ',', $conf->MCServers ) ); + foreach ( $conf->MCServerArray as $server ) { + $error = testMemcachedServer( $server ); + if ( $error ) { + $errs["MCServers"] = $error; + break; + } + } +} else if ( $conf->Shm == 'memcached' ) { + $errs["MCServers"] = "Please specify at least one server if you wish to use memcached"; +} + if( $conf->posted && ( 0 == count( $errs ) ) ) { do { /* So we can 'continue' to end prematurely */ $conf->Root = ($conf->RootPW != ""); @@ -690,7 +716,30 @@ if( count( $errs ) ) { wiki database, a sysop account will be created with the given name and password. - + +
    + +
    Select one:
    + + +
    +
    + Using a shared memory system such as Turck MMCache or Memcached will speed + up MediaWiki significantly. Memcached is the best solution but needs to be + installed. Specify the server addresses and ports in a comma-separted list. Only + use Turck shared memory if the wiki will be running on a single Apache server. +

    Database config

    @@ -784,6 +833,24 @@ function writeLocalSettings( $conf ) { $pretty = ($conf->prettyURLs ? "" : "# "); $ugly = ($conf->prettyURLs ? "# " : ""); $rights = ($conf->RightsUrl) ? "" : "# "; + + switch ( $conf->Shm ) { + case 'memcached': + $memcached = 'true'; + $turck = '#'; + $mcservers = var_export( $conf->MCServerArray, true ); + break; + case 'turck': + $memcached = 'false'; + $mcservers = 'array()'; + $turck = ''; + break; + default: + $memcached = 'false'; + $mcservers = 'array()'; + $turck = '#'; + } + $file = @fopen( "/dev/urandom", "r" ); if ( $file ) { @@ -863,6 +930,11 @@ if ( \$wgCommandLineMode ) { \$wgDBmysql4 = \$wgEnablePersistentLC = {$conf->DBmysql4}; +## Shared memory settings +\$wgUseMemcached = $memcached; +\$wgMemCachedServers = $mcservers; +{$turck}\$wgUseTurckShm = function_exists( 'mmcache_get' ) && php_sapi_name() == 'apache'; + ## To enable image uploads, make sure the 'images' directory ## is writable, then uncomment this: # \$wgDisableUploads = false; @@ -988,6 +1060,50 @@ function getLanguageList() { return $codes; } +# Test a memcached server +function testMemcachedServer( $server ) { + $hostport = explode(":", $server); + $errstr = false; + $fp = false; + if ( !function_exists( 'fsockopen' ) ) { + $errstr = "Can't connect to memcached, fsockopen() not present"; + } + if ( !$errstr && count( $hostport ) != 2 ) { + $errstr = 'Please specify host and port'; + var_dump( $hostport ); + } + if ( !$errstr ) { + list( $host, $port ) = $hostport; + $errno = 0; + $fsockerr = ''; + + $fp = @fsockopen( $host, $port, $errno, $fsockerr, 1.0 ); + if ( $fp === false ) { + $errstr = "Cannot connect to memcached on $host:$port : $fsockerr"; + } + } + if ( !$errstr ) { + $command = "version\r\n"; + $bytes = fwrite( $fp, $command ); + if ( $bytes != strlen( $command ) ) { + $errstr = "Cannot write to memcached socket on $host:$port"; + } + } + if ( !$errstr ) { + $expected = "VERSION "; + $response = fread( $fp, strlen( $expected ) ); + if ( $response != $expected ) { + $errstr = "Didn't get correct memcached response from $host:$port"; + } + } + if ( $fp ) { + fclose( $fp ); + } + if ( !$errstr ) { + echo "
  • Connected to memcached on $host:$port successfully"; + } + return $errstr; +} ?> diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index afabae98ab..9ea4796481 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -280,7 +280,7 @@ $wgLinkCacheMemcached = false; # Not fully tested * * @global bool $wgUseTurckShm Enable or disabled Turck MMCache */ -$wgUseTurckShm = function_exists( 'mmcache_get' ) && php_sapi_name() == 'apache'; +$wgUseTurckShm = false; # Language settings -- 2.20.1