PHP API 1.0.7

Brion Vibber brion@pobox.com
Sat, 09 Aug 2003 23:49:47 -0700


This is a multi-part message in MIME format.
--------------060402060905030606060808
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Ryan Gilfether wrote:

> A new version of the PHP API has been completed, verson 1.0.7. 


Cool! Where can I find it?

I'm doing some preliminary work on getting memcached support into 
Wikipedia (or rather MediaWiki, as we've recently redubbed the software 
thereof), so far I've started with the 1.0.6 PHP client.

> Along with that 3 new function have been added
> error() - returns an error code for the last error genterated
> error_string() - returns a string with a description of the error
> error_clear() - clears the last error 


On a related note, the debug mode doesn't mix well with MediaWiki's 
output model. I replaced all the "print"s with calls to a _debug() 
private function which can I can then override in a subclass to dump 
things to our debug log; diff for 1.0.6 attached.

-- brion vibber (brion @ pobox.com)

--------------060402060905030606060808
Content-Type: text/plain;
 name="php-memc-debug.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="php-memc-debug.diff"

--- /home/brion/src/php-memcached-1.0.6/MemCachedClient.inc.php	Mon Jul 28 19:04:24 2003
+++ MemCachedClient.inc.php	Sat Aug  9 23:35:19 2003
@@ -74,7 +74,7 @@
 		if(!$this->active)
 		{
 			if($this->debug)
-				print "delete(): There are no active servers available\r\n";
+				$this->_debug("delete(): There are no active servers available");
 
 			return FALSE;
 		}
@@ -104,7 +104,7 @@
             	if($this->debug)
 				{
 					$errno = socket_last_error($sock);
-					print "_delete(): socket_write() returned FALSE. Error $errno: ".socket_strerror($errno)."\r\n";
+					$this->_debug("_delete(): socket_write() returned FALSE. Error $errno: ".socket_strerror($errno));
 				}
 
 				return FALSE;
@@ -117,7 +117,7 @@
 			if($this->debug)
 			{
 				$errno = socket_last_error($sock);
-				print "_delete(): socket_read() returned FALSE. Error $errno: ".socket_strerror($errno)."\r\n";
+				$this->_debug("_delete(): socket_read() returned FALSE. Error $errno: ".socket_strerror($errno));
 			}
 
 			return FALSE;
@@ -131,7 +131,7 @@
 			return TRUE;
 
         if($this->debug)
-			print "_delete(): Failed to receive DELETED response from server. Received $retval instead.\r\n";
+			$this->_debug("_delete(): Failed to receive DELETED response from server. Received $retval instead.");
 
 		return FALSE;
 	}
@@ -220,7 +220,7 @@
 		if($this->debug)
 		{
 			while(list($k, $v) = each($val))
-				print "MemCache: got $k = $v\n";
+				$this->_debug("MemCache: got $k = $v");
 		}
 
 		return $val;
@@ -263,7 +263,7 @@
 		if(count($conn) != 2)
 		{
 			if($this->debug)
-				print "sock_to_host(): Host address was not in the format of host:port\r\n";
+				$this->_debug("sock_to_host(): Host address was not in the format of host:port");
 
 			return FALSE;
 		}
@@ -272,7 +272,7 @@
 		($this->host_dead[$conn[0]] && $this->host_dead[$conn[0]] > $now))
 		{
 			if($this->debug)
-				print "sock_to_host(): The host $host is not available.\r\n";
+				$this->_debug("sock_to_host(): The host $host is not available.");
 
 			return FALSE;
 		}
@@ -286,7 +286,7 @@
 			$this->host_dead[$host]=$this->host_dead[$conn[0]]=$now+60+intval(rand(0, 10));
 
 			if($this->debug)
-				print "sock_to_host(): Failed to connect to ".$conn[0].":".$conn[1]."\r\n";
+				$this->_debug("sock_to_host(): Failed to connect to ".$conn[0].":".$conn[1]);
 
 			return FALSE;
 		}
@@ -304,7 +304,7 @@
 		if(!$this->active)
 		{
 			if($this->debug)
-				print "get_sock(): There are no active servers available\r\n";
+				$this->_debug("get_sock(): There are no active servers available");
 
 			return FALSE;
 		}
@@ -344,7 +344,7 @@
 		}
 
 		if($this->debug)
-			print "get_sock(): get_sock(): Unable to retrieve a valid socket\r\n";
+			$this->_debug("get_sock(): get_sock(): Unable to retrieve a valid socket");
 
 		return FALSE;
 	}
@@ -359,7 +359,7 @@
 		if(!$this->active)
 		{
 			if($this->debug)
-				print "_incrdecr(): There are no active servers available\r\n";
+				$this->_debug("_incrdecr(): There are no active servers available");
 
 			return FALSE;
 		}
@@ -368,7 +368,7 @@
 		if(!is_resource($sock))
 		{
 			if($this->debug)
-				print "_incrdecr(): Invalid socket returned by get_sock()\r\n";
+				$this->_debug("_incrdecr(): Invalid socket returned by get_sock()");
 
 			return FALSE;
 		}
@@ -394,7 +394,7 @@
             	if($this->debug)
 				{
 					$errno = socket_last_error($sock);
-					print "_incrdecr(): socket_write() returned FALSE. Error $errno: ".socket_strerror($errno)."\r\n";
+					$this->_debug("_incrdecr(): socket_write() returned FALSE. Error $errno: ".socket_strerror($errno));
 				}
 
 				return FALSE;
@@ -405,7 +405,7 @@
 		if(($retval = socket_read($sock, MC_BUFFER_SZ, PHP_NORMAL_READ)) === FALSE)
 		{
 			$errno = socket_last_error($sock);
-			print "_incrdecr(): socket_read() returned FALSE. Error $errno: ".socket_strerror($errno)."\r\n";
+			$this->_debug("_incrdecr(): socket_read() returned FALSE. Error $errno: ".socket_strerror($errno));
 		}
 
 		// strip the /r/n from the end
@@ -424,7 +424,7 @@
 		if(!$this->active)
 		{
 			if($this->debug)
-				print "_set(): There are no active servers available\r\n";
+				$this->_debug("_set(): There are no active servers available");
 
 			return FALSE;
 		}
@@ -433,7 +433,7 @@
 		if(!is_resource($sock))
 		{
 			if($this->debug)
-				print "_set(): Invalid socket returned by get_sock()\r\n";
+				$this->_debug("_set(): Invalid socket returned by get_sock()");
 
 			return FALSE;
 		}
@@ -472,7 +472,7 @@
             	if($this->debug)
 				{
 					$errno = socket_last_error($sock);
-					print "_set(): socket_write() returned FALSE. Error $errno: ".socket_strerror($errno)."\r\n";
+					$this->_debug("_set(): socket_write() returned FALSE. Error $errno: ".socket_strerror($errno));
 				}
 
 				return FALSE;
@@ -485,7 +485,7 @@
 			if($this->debug)
 			{
 				$errno = socket_last_error($sock);
-				print "_set(): socket_read() returned FALSE. Error $errno: ".socket_strerror($errno)."\r\n";
+				$this->_debug("_set(): socket_read() returned FALSE. Error $errno: ".socket_strerror($errno));
 			}
 
 			return FALSE;
@@ -494,13 +494,13 @@
 		if($l_szResponse == "STORED")
 		{
 			if($this->debug)
-				print "MemCache: $cmdname $key = $raw_val\n";
+				$this->_debug("MemCache: $cmdname $key = $raw_val");
 
 			return TRUE;
 		}
 
 		if($this->debug)
-			print "_set(): Did not receive STORED as the server response! Received $l_szResponse instead\r\n";
+			$this->_debug("_set(): Did not receive STORED as the server response! Received $l_szResponse instead");
 
 		return FALSE;
 	}
@@ -536,7 +536,7 @@
             	if($this->debug)
 				{
 					$errno = socket_last_error($sock);
-					print "_load_items(): socket_write() returned FALSE. Error $errno: ".socket_strerror($errno)."\r\n";
+					$this->_debug("_load_items(): socket_write() returned FALSE. Error $errno: ".socket_strerror($errno));
 				}
 
 				return FALSE;
@@ -556,7 +556,7 @@
 				if($this->debug)
 				{
 					$errno = socket_last_error($sock);
-					print "_load_items(): socket_read() returned FALSE. Error $errno: ".socket_strerror($errno)."\r\n";
+					$this->_debug("_load_items(): socket_read() returned FALSE. Error $errno: ".socket_strerror($errno));
 				}
 
 				return FALSE;
@@ -584,7 +584,7 @@
 				{
 					// something went wrong, we never recieved the header
 					if($this->debug)
-						print "_load_items(): Failed to recieve valid header!\r\n";
+						$this->_debug("_load_items(): Failed to recieve valid header!");
 
 					return FALSE;
 				}
@@ -625,7 +625,7 @@
 				else
 				{
                 	if($this->debug)
-						print "_load_items(): Failed to receive END. Received $end instead.\r\n";
+						$this->_debug("_load_items(): Failed to receive END. Received $end instead.");
 
 					return FALSE;
 				}
@@ -635,7 +635,7 @@
 			if($bytes_read > ($len + 7))
 			{
 				if($this->debug)
-					print "_load_items(): Bytes read is greater than requested data size!\r\n";
+					$this->_debug("_load_items(): Bytes read is greater than requested data size!");
 
 				return FALSE;
 			}
@@ -656,6 +656,10 @@
 
 		return $hash;
 	}
+	
+	function _debug($text) {
+		print $text . "\r\n";
+	}
 }
 
 /*
@@ -672,12 +676,3 @@
  * http://www.gilfether.com
  */
 ?>
-
-
-
-
-
-
-
-
-

--------------060402060905030606060808--