<?php
-//
-// +---------------------------------------------------------------------------+
-// | memcached client, PHP |
-// +---------------------------------------------------------------------------+
-// | Copyright (c) 2003 Ryan T. Dean <rtdean@cytherianage.net> |
-// | All rights reserved. |
-// | |
-// | Redistribution and use in source and binary forms, with or without |
-// | modification, are permitted provided that the following conditions |
-// | are met: |
-// | |
-// | 1. Redistributions of source code must retain the above copyright |
-// | notice, this list of conditions and the following disclaimer. |
-// | 2. Redistributions in binary form must reproduce the above copyright |
-// | notice, this list of conditions and the following disclaimer in the |
-// | documentation and/or other materials provided with the distribution. |
-// | |
-// | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
-// | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
-// | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
-// | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
-// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
-// | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
-// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
-// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
-// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
-// | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-// +---------------------------------------------------------------------------+
-// | Author: Ryan T. Dean <rtdean@cytherianage.net> |
-// | Heavily influenced by the Perl memcached client by Brad Fitzpatrick. |
-// | Permission granted by Brad Fitzpatrick for relicense of ported Perl |
-// | client logic under 2-clause BSD license. |
-// +---------------------------------------------------------------------------+
-//
-// $TCAnet$
-//
+/**
+ * +---------------------------------------------------------------------------+
+ * | memcached client, PHP |
+ * +---------------------------------------------------------------------------+
+ * | Copyright (c) 2003 Ryan T. Dean <rtdean@cytherianage.net> |
+ * | All rights reserved. |
+ * | |
+ * | Redistribution and use in source and binary forms, with or without |
+ * | modification, are permitted provided that the following conditions |
+ * | are met: |
+ * | |
+ * | 1. Redistributions of source code must retain the above copyright |
+ * | notice, this list of conditions and the following disclaimer. |
+ * | 2. Redistributions in binary form must reproduce the above copyright |
+ * | notice, this list of conditions and the following disclaimer in the |
+ * | documentation and/or other materials provided with the distribution. |
+ * | |
+ * | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
+ * | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
+ * | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
+ * | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
+ * | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
+ * | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
+ * | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ * +---------------------------------------------------------------------------+
+ * | Author: Ryan T. Dean <rtdean@cytherianage.net> |
+ * | Heavily influenced by the Perl memcached client by Brad Fitzpatrick. |
+ * | Permission granted by Brad Fitzpatrick for relicense of ported Perl |
+ * | client logic under 2-clause BSD license. |
+ * +---------------------------------------------------------------------------+
+ *
+ * @file
+ * $TCAnet$
+ */
/**
* This is the PHP client for memcached - a distributed memory cache daemon.
*/
public function __construct( $args ) {
global $wgMemCachedTimeout;
- $this->set_servers( @$args['servers'] );
- $this->_debug = @$args['debug'];
+ $this->set_servers( isset( $args['servers'] ) ? $args['servers'] : array() );
+ $this->_debug = isset( $args['debug'] ) ? $args['debug'] : false;
$this->stats = array();
- $this->_compress_threshold = @$args['compress_threshold'];
- $this->_persistant = array_key_exists( 'persistant', $args ) ? ( @$args['persistant'] ) : false;
+ $this->_compress_threshold = isset( $args['compress_threshold'] ) ? $args['compress_threshold'] : 0;
+ $this->_persistant = isset( $args['persistant'] ) ? $args['persistant'] : false;
$this->_compress_enable = true;
$this->_have_zlib = function_exists( 'gzcompress' );
$key = is_array( $key ) ? $key[1] : $key;
- @$this->stats['delete']++;
+ if ( isset( $this->stats['delete'] ) ) {
+ $this->stats['delete']++;
+ } else {
+ $this->stats['delete'] = 1;
+ }
$cmd = "delete $key $time\r\n";
if( !$this->_safe_fwrite( $sock, $cmd, strlen( $cmd ) ) ) {
$this->_dead_sock( $sock );
return false;
}
- @$this->stats['get']++;
+ if ( isset( $this->stats['get'] ) ) {
+ $this->stats['get']++;
+ } else {
+ $this->stats['get'] = 1;
+ }
$cmd = "get $key\r\n";
if ( !$this->_safe_fwrite( $sock, $cmd, strlen( $cmd ) ) ) {
return false;
}
- @$this->stats['get_multi']++;
+ if ( isset( $this->stats['get_multi'] ) ) {
+ $this->stats['get_multi']++;
+ } else {
+ $this->stats['get_multi'] = 1;
+ }
$sock_keys = array();
foreach ( $keys as $key ) {
$timeout = $this->_connect_timeout;
$errno = $errstr = null;
for( $i = 0; !$sock && $i < $this->_connect_attempts; $i++ ) {
+ wfSuppressWarnings();
if ( $this->_persistant == 1 ) {
- $sock = @pfsockopen( $ip, $port, $errno, $errstr, $timeout );
+ $sock = pfsockopen( $ip, $port, $errno, $errstr, $timeout );
} else {
- $sock = @fsockopen( $ip, $port, $errno, $errstr, $timeout );
+ $sock = fsockopen( $ip, $port, $errno, $errstr, $timeout );
}
+ wfRestoreWarnings();
}
if ( !$sock ) {
if ( $this->_debug ) {
}
function _dead_host( $host ) {
- @list( $ip, /* $port */) = explode( ':', $host );
+ $parts = explode( ':', $host );
+ $ip = $parts[0];
$this->_host_dead[$ip] = time() + 30 + intval( rand( 0, 10 ) );
$this->_host_dead[$host] = $this->_host_dead[$ip];
unset( $this->_cache_sock[$host] );
}
$key = is_array( $key ) ? $key[1] : $key;
- @$this->stats[$cmd]++;
+ if ( isset( $this->stats[$cmd] ) ) {
+ $this->stats[$cmd]++;
+ } else {
+ $this->stats[$cmd] = 1;
+ }
if ( !$this->_safe_fwrite( $sock, "$cmd $key $amt\r\n" ) ) {
return $this->_dead_sock( $sock );
}
}
$offset += $n;
$bneed -= $n;
- @$ret[$rkey] .= $data;
+ if ( isset( $ret[$rkey] ) ) {
+ $ret[$rkey] .= $data;
+ } else {
+ $ret[$rkey] = $data;
+ }
}
if ( $offset != $len + 2 ) {
return false;
}
- @$this->stats[$cmd]++;
+ if ( isset( $this->stats[$cmd] ) ) {
+ $this->stats[$cmd]++;
+ } else {
+ $this->stats[$cmd] = 1;
+ }
$flags = 0;