This commit is contained in:
2019-02-06 00:49:12 +03:00
commit 8dbb1bb605
4796 changed files with 506072 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
Release 1.0.10
--------------
* bug fix: changes hashing function to crc32, sprintf %u
* feature: optional compression
Release 1.0.9
-------------
* protocol parsing bug
Release 1.0.8
-------------
* whitespace/punctuation/wording cleanups
Release 1.0.7
-------------
* added 3 functions which handle error reporting
error() - returns error number of last error generated, else returns 0
error_string() - returns a string description of error number retuned
error_clear() - clears the last error number and error string
* removed call to preg_match() in _loaditems()
* only non-scalar values are serialize() before being
sent to the server
* added the optional timestamp argument for delete()
read Documentation file for details
* PHPDocs/PEAR style comments added
* abstract debugging (Brion Vibber <brion@pobox.com>)
Release 1.0.6
-------------
* removed all array_push() calls
* applied patch provided by Stuart Herbert<stuart@gentoo.org>
corrects possible endless loop. Available at
http://bugs.gentoo.org/show_bug.cgi?id=25385
* fixed problem with storing large binary files
* added more error checking, specifically on all socket functions
* added support for the INCR and DECR commands
which increment or decrement a value stored in MemCached
* Documentation removed from source and is now available
in the file Documentation
Release 1.0.4
-------------
* initial release, version numbers kept
in sync with MemCached version
* capable of storing any datatype in MemCached

View File

@@ -0,0 +1,258 @@
Ryan Gilfether <hotrodder@rocketmail.com>
http://www.gilfether.com
This module is Copyright (c) 2003 Ryan Gilfether.
All rights reserved.
You may distribute under the terms of the GNU General Public License
This is free software. IT COMES WITHOUT WARRANTY OF ANY KIND.
See the memcached website: http://www.danga.com/memcached/
// Takes one parameter, a array of options. The most important key is
// options["servers"], but that can also be set later with the set_servers()
// method. The servers must be an array of hosts, each of which is
// either a scalar of the form <10.0.0.10:11211> or an array of the
// former and an integer weight value. (the default weight if
// unspecified is 1.) It's recommended that weight values be kept as low
// as possible, as this module currently allocates memory for bucket
// distribution proportional to the total host weights.
// $options["debug"] turns the debugging on if set to true
MemCachedClient::MemCachedClient($options);
// sets up the list of servers and the ports to connect to
// takes an array of servers in the same format as in the constructor
MemCachedClient::set_servers($servers);
// Retrieves a key from the memcache. Returns the value (automatically
// unserialized, if necessary) or FALSE if it fails.
// The $key can optionally be an array, with the first element being the
// hash value, if you want to avoid making this module calculate a hash
// value. You may prefer, for example, to keep all of a given user's
// objects on the same memcache server, so you could use the user's
// unique id as the hash value.
// Possible errors set are:
// MC_ERR_GET
MemCachedClient::get($key);
// just like get(), but takes an array of keys, returns FALSE on error
// Possible errors set are:
// MC_ERR_NOT_ACTIVE
MemCachedClient::get_multi($keys)
// Unconditionally sets a key to a given value in the memcache. Returns true
// if it was stored successfully.
// The $key can optionally be an arrayref, with the first element being the
// hash value, as described above.
// returns TRUE on success else FALSE
// Possible errors set are:
// MC_ERR_NOT_ACTIVE
// MC_ERR_GET_SOCK
// MC_ERR_SOCKET_WRITE
// MC_ERR_SOCKET_READ
// MC_ERR_SET
MemCachedClient::set($key, $value, $exptime);
// Like set(), but only stores in memcache if the key doesn't already exist.
// returns TRUE on success else FALSE
// Possible errors set are:
// MC_ERR_NOT_ACTIVE
// MC_ERR_GET_SOCK
// MC_ERR_SOCKET_WRITE
// MC_ERR_SOCKET_READ
// MC_ERR_SET
MemCachedClient::add($key, $value, $exptime);
// Like set(), but only stores in memcache if the key already exists.
// returns TRUE on success else FALSE
// Possible errors set are:
// MC_ERR_NOT_ACTIVE
// MC_ERR_GET_SOCK
// MC_ERR_SOCKET_WRITE
// MC_ERR_SOCKET_READ
// MC_ERR_SET
MemCachedClient::replace($key, $value, $exptime);
// removes the key from the MemCache
// $time is the amount of time in seconds (or Unix time) until which
// the client wishes the server to refuse "add" and "replace" commands
// with this key. For this amount of item, the item is put into a
// delete queue, which means that it won't possible to retrieve it by
// the "get" command, but "add" and "replace" command with this key
// will also fail (the "set" command will succeed, however). After the
// time passes, the item is finally deleted from server memory.
// The parameter $time is optional, and, if absent, defaults to 0
// (which means that the item will be deleted immediately and further
// storage commands with this key will succeed).
// returns TRUE on success else returns FALSE
// Possible errors set are:
// MC_ERR_NOT_ACTIVE
// MC_ERR_GET_SOCK
// MC_ERR_SOCKET_WRITE
// MC_ERR_SOCKET_READ
// MC_ERR_DELETE
MemCachedClient::delete($key, $time = 0);
// Sends a command to the server to atomically increment the value for
// $key by $value, or by 1 if $value is undefined. Returns FALSE if $key
// doesn't exist on server, otherwise it returns the new value after
// incrementing. Value should be zero or greater. Overflow on server
// is not checked. Be aware of values approaching 2**32. See decr.
// Possible errors set are:
// MC_ERR_NOT_ACTIVE
// MC_ERR_GET_SOCK
// MC_ERR_SOCKET_WRITE
// MC_ERR_SOCKET_READ
// returns new value on success, else returns FALSE
// ONLY WORKS WITH NUMERIC VALUES
MemCachedClient::incr($key[, $value]);
// Like incr, but decrements. Unlike incr, underflow is checked and new
// values are capped at 0. If server value is 1, a decrement of 2
// returns 0, not -1.
// Possible errors set are:
// MC_ERR_NOT_ACTIVE
// MC_ERR_GET_SOCK
// MC_ERR_SOCKET_WRITE
// MC_ERR_SOCKET_READ
// returns new value on success, else returns FALSE
// ONLY WORKS WITH NUMERIC VALUES
MemCachedClient::decr($key[, $value]);
// disconnects from all servers
MemCachedClient::disconnect_all();
// if $do_debug is set to true, will print out
// debugging info, else debug is turned off
MemCachedClient::set_debug($do_debug);
// remove all cached hosts that are no longer good
MemCachedClient::forget_dead_hosts();
// When a function returns FALSE, an error code is set.
// This funtion will return the error code.
// See error_string()
// returns last error code set
MemCachedClient::error()
// Returns a string describing the error set in error()
// See error()
// returns a string describing the error code given
MemCachedClient::error_string()
// Resets the error number and error string
MemCachedClient::error_clear()
Error codes are as follows:
MC_ERR_NOT_ACTIVE // no active servers
MC_ERR_SOCKET_WRITE // socket_write() failed
MC_ERR_SOCKET_READ // socket_read() failed
MC_ERR_SOCKET_CONNECT // failed to connect to host
MC_ERR_DELETE // delete() did not recieve DELETED command
MC_ERR_HOST_FORMAT // sock_to_host() invalid host format
MC_ERR_HOST_DEAD // sock_to_host() host is dead
MC_ERR_GET_SOCK // get_sock() failed to find a valid socket
MC_ERR_SET // _set() failed to receive the STORED response
MC_ERR_LOADITEM_HEADER // _load_items failed to receive valid data header
MC_ERR_LOADITEM_END // _load_items failed to receive END response
MC_ERR_LOADITEM_BYTES // _load_items bytes read larger than bytes available
MC_ERR_GET // failed to get value associated with key
// Turns compression on or off; 0=off, 1=on
MemCacheClient::set_compression($setting)
EXAMPLE:
<?php
require("MemCachedClient.inc.php");
// set the servers, with the last one having an interger weight value of 3
$options["servers"] = array("10.0.0.15:11000","10.0.0.16:11001",array("10.0.0.17:11002", 3));
$options["debug"] = false;
$memc = new MemCachedClient($options);
/***********************
* STORE AN ARRAY
***********************/
$myarr = array("one","two", 3);
$memc->set("key_one", $myarr);
$val = $memc->get("key_one");
print $val[0]."\n"; // prints 'one'
print $val[1]."\n"; // prints 'two'
print $val[2]."\n"; // prints 3
print "\n";
/***********************
* STORE A CLASS
***********************/
class tester
{
var $one;
var $two;
var $three;
}
$t = new tester;
$t->one = "one";
$t->two = "two";
$t->three = 3;
$memc->set("key_two", $t);
$val = $memc->get("key_two");
print $val->one."\n";
print $val->two."\n";
print $val->three."\n";
print "\n";
/***********************
* STORE A STRING
***********************/
$memc->set("key_three", "my string");
$val = $memc->get("key_three");
print $val; // prints 'my string'
$memc->delete("key_one");
$memc->delete("key_two");
$memc->delete("key_three");
$memc->disconnect_all();
print "\n";
/***********************
* STORE A BINARY FILE
***********************/
// first read the file and save it in memcache
$fp = fopen( "./image.jpg", "rb" ) ;
if ( !$fp )
{
print "Could not open ./file.dat!\n" ;
exit ;
}
$data = fread( $fp, filesize( "./image.jpg" ) ) ;
fclose( $fp ) ;
print "Data length is " . strlen( $data ) . "\n" ;
$memc->set( "key", $data ) ;
// now open a file for writing and write the data
// retrieved from memcache
$fp = fopen("./test.jpg","wb");
$data = $memc->get( "key" ) ;
print "Data length is " . strlen( $data ) . "\n" ;
fwrite($fp,$data,strlen( $data ));
fclose($fp);
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,70 @@
#!/usr/bin/perl
#
# Simplify Brad's life. I'm sure there's a PHP-specific way
# to do this (or there should be), but I don't do the PHP,
# so this is my answer.
#
# Heavily documented for the PHP programmers who might be
# reading this.
#
use strict;
use Getopt::Long;
my $opt_tar = 0;
my $opt_upload = 0;
exit 1 unless GetOptions("tar" => \$opt_tar,
"upload" => \$opt_upload);
# chdir to the directory the script's at, so future
# paths need only be relative
use FindBin qw($Bin);
chdir $Bin or die "Couldn't cd to $Bin\n";
die "Must use --tar or --upload\n" unless $opt_tar || $opt_upload;
# files to distribute
my @manifest = qw(
ChangeLog
Documentation
MemCachedClient.inc.php
);
# figure out the version number
open (PHP, "MemCachedClient.inc.php") or die;
{ local $/ = undef; $_ = <PHP>; } # suck in the whole file
close PHP;
die "Can't find version number\n" unless
/MC_VERSION.+?(\d[^\'\"]+)/s;
my $ver = $1;
my $dir = "php-memcached-$ver";
my $dist = "$dir.tar.gz";
if ($opt_tar) {
# make a fresh directory
mkdir $dir or die "Couldn't make directory: $dir\n";
# copy files to fresh directory
foreach my $file (@manifest) {
system("cp", $file, "$dir/$file")
and die "Error copying file $file\n";
}
# tar it up
system("tar", "zcf", $dist, $dir)
and die "Error running tar.\n";
# remove temp directory
system("rm", "-rf", $dir)
and die "Error cleaning up temp directory\n";
print "$dist created.\n";
}
if ($opt_upload) {
print "Uploading $dist...\n";
system("scp", $dist, 'bradfitz@danga.com:memd/dist/')
and die "Error uploading to memcached/dist\n";
}
print "Done.\n";