6.0.0-git
2019-04-25

[#2781] Enhancements for memcache session driver
Summary Enhancements for memcache session driver
Queue Horde Framework Packages
Queue Version HEAD
Type Enhancement
State Resolved
Priority 1. Low
Owners
Requester kevin_myer (at) iu13 (dot) org
Created 2005-10-14 (4941 days ago)
Due
Updated 2005-10-17 (4938 days ago)
Assigned
Resolved 2005-10-17 (4938 days ago)
Milestone
Patch No

History
2005-10-17 20:43:20 Jan Schneider Comment #9
State ⇒ Resolved
Reply to this comment
Cleaned up and committed, thanks.
2005-10-17 20:35:34 Jan Schneider Deleted Original Message
 
2005-10-17 19:51:33 kevin_myer (at) iu13 (dot) org Comment #8 Reply to this comment
Summary of enhancements over original driver:
And forgot to add, debug logging, if logging at PEAR_LOG_DEBUG level.
2005-10-17 19:39:39 kevin_myer (at) iu13 (dot) org Comment #7
New Attachment: memcached.php.patch Download
Reply to this comment
Looks much better, but I still have two suggestions:
- the operators in _getConForId() need some more horizontel whitespace
Sorry missed that.  It might be helpful if the CODING_STANDARDS 
webpage had a fixed font specified, as it's somewhat difficult to 
pickup the spacing from there.  I know I could look the same doc up in 
a terminal window but a Courier font would help the webpage.
- I personally would prefer to use the functional interface to the
memcached extension. The OO interface doesn't gain us anything here
is probably not available in older versions of the extension.
I'll change it.  I had used  pure OO code 
$foo=$bar->getConId($id)->get($id) but that didn't work under PHP 4, 
so I had partially backed it out but its not much of a difference to 
use the functional interface, and maybe easier to read.



I think this will be the extent of how far this particular session 
handler, using the PECL memcache extension can really go.  With 
libmemcache and the php-mcache, more robust configurations with easier 
failover are possible, but since the base PECL memcache functions 
don't support multiple servers, I think a different driver based on a 
different memcache library would be better.  The downside to that is 
an additional dependency but anyone who needs that kind of reliability 
has probably already worked out something in-house anyway.  But it 
would be nice to get something into public code, so us smaller players 
don't have as much to maintain locally.



Summary of enhancements over original driver:

Ability to specify more than one server (but no automatic failover of 
data for downed servers)

Ability to specify persistent connections

Ability to specify compression of data




2005-10-17 10:56:08 Jan Schneider Deleted Original Message
 
2005-10-17 10:55:43 Jan Schneider Comment #6 Reply to this comment
Looks much better, but I still have two suggestions:

- the operators in _getConForId() need some more horizontel whitespace

- I personally would prefer to use the functional interface to the 
memcached extension. The OO interface doesn't gain us anything here is 
probably not available in older versions of the extension.
2005-10-16 02:24:12 kevin_myer (at) iu13 (dot) org Comment #5
New Attachment: memcached.php[1].patch
Reply to this comment
Here is a cleaned up patch, which I think complies with coding 
standards (at least better than the first one).  Minor code 
adjustments to the first patch - removed extra persistent check in the 
close function and took the connect/pconnect logic outside the loop 
for the _connect function.



This seems to work on OpenBSD 3.7, with Apache/1.3.29 (Unix) 
PHP/5.0.4, although something is causing Apache to segfault.



Because of the way RHEL 4 handles malloc/free calls that fail, this 
code doesn't work on RHEL 4, as glibc throws an exception.



So can someone spot what I'm doing wrong?  Or am I running into a bug 
in the PECL memcache extension?




2005-10-14 12:37:25 kevin_myer (at) iu13 (dot) org Comment #4 Reply to this comment
But there are a bunch of coding style issues, like indenting,
horizontal whitespace, curly braces placement, etc. Can you update
your patch accordingly?
Will do.  I had the bright idea to try and use a Windows GUI to code 
the changes and it was not a good idea at all...  So back to vi..


2005-10-14 07:28:03 Jan Schneider Comment #3
State ⇒ Feedback
Reply to this comment
The enhancements are fine, the stringlists should work too.



But there are a bunch of coding style issues, like indenting, 
horizontal whitespace, curly braces placement, etc. Can you update 
your patch accordingly?
2005-10-14 03:04:49 kevin_myer (at) iu13 (dot) org Comment #2
New Attachment: horde-conf.xml.patch Download
Reply to this comment
And the conf.xml patch..
2005-10-14 03:04:17 kevin_myer (at) iu13 (dot) org Comment #1
Type ⇒ Enhancement
State ⇒ New
Priority ⇒ 1. Low
Summary ⇒ Enhancements for memcache session driver
Queue ⇒ Horde Framework Packages
New Attachment: memcached.php.patch Download
Reply to this comment
This is a first crack at adding some enhancements and robustness to 
the memcache driver.



Enhancements:

Support for persistent connections 
($conf['sessionhandler']['params']['persistent']

Support for compression ($conf['sessionhandler']['params']['compression']

Support for multiple servers, comma separated 'hostspec' and 'port' 
values (is there a cleaner way to do this??)



Sessions are hashed to determine what server they should be stored on 
and all read/write/delete functions are passed through this function 
to get the proper connection.



The ideas for this are synthesized from the various generic and 
session-specific memcache implementations in APIs I've found.  The 
hash function to determine the server to write the session to is 
supposed to distribute the values the most evenly and be the higher 
performance function for those available.



TODO:

Test extensively (works for me, with one bogus server in my config, 
representing a down server, and one real server, but the usual no 
warranty implied, don't use in healthcare settings, etc. applies)

Add support for down server detection, with a timer to repoll down 
servers to see if they've come back.  $_connected should probably be 
an array which maintains up/down state for each potential connection.

Add support for session enumeration (with memcached, 'stats items' 
yields a list of the buckets, 'stats cachedump bucket#' would yield 
the sessionid, both of  which I think can be mapped to PHP memcache 
stat functions, or a stat function can be written that returns a list 
of sessionids)

Add a prefix to the sessionid so multiple sites sessions can be stored 
in the same set of memcached servers, but can be enumerated by each 
separate site

Better error handling and logging

Saved Queries