php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63272 Explicitly reserve range of flags in php_memcache.h so application code can use
Submitted: 2012-10-13 05:56 UTC Modified: 2012-11-04 19:35 UTC
From: stevenschow at yahoo dot com Assigned: hradtke (profile)
Status: Closed Package: memcache (PECL)
PHP Version: 5.4.7 OS: Linux
Private report: No CVE-ID: None
 [2012-10-13 05:56 UTC] stevenschow at yahoo dot com
Description:
------------
Sometimes it can be useful to store some data in the memcache flags.  For 
example, 
if one has a compression or encoding you'd like to use besides the built in php 
serialized (indicated by "MMC_SERIALIZED") or MMC_COMPRESSED it can be useful to 
pass in an additional flag setting into memcache->set and get.  This already 
works 
as described however there is no guarantee that future versions of pecl-memcache 
will not use the same flags an application has choosen to use.

My feature request is simply to explicitly reserve some range of the flags and 
add 
some comments and/or defines in php_memcache.h (and php docs) so that 
applications 
know which flags they can use safely.  For example add something like this to 
php_memcache.h just after MMC_COMPRESSED:

// These flags are set here to reserve the for use by users of the pecl-memcache  
set and get
#define MMC_RESERVED_FLAGS_APPLICATIONDEFINED_12 4096  // 1<<12
#define MMC_RESERVED_FLAGS_APPLICATIONDEFINED_13 8192  // 1<<13
#define MMC_RESERVED_FLAGS_APPLICATIONDEFINED_14 16384  // 1<<14
#define MMC_RESERVED_FLAGS_APPLICATIONDEFINED_15 32768  // 1<<15

Test script:
---------------
$m = new Memcache();

define('MEMCACHE_APPFLAG_JSON', 4096);
$flags = MEMCACHE_APPFLAG_JSON;
$flags = $flags | MEMCACHE_COMPRESSED;
$m->set("testkey", "testvalue", $flags);

$getflags = 0;
$m->get("testkey", $getflags);

// At this point we know that I can get MEMCACHE_APPFLAG_JSON back out without
// worrying that a newer version of php_memcache may have inadvertantly 
// used the same bit for something else.


Patches

php_memcache.h (last revision 2012-10-13 06:05 UTC by stevenschow at yahoo dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-26 20:24 UTC] adam at adamhahn dot com
I agree. I have been using non-reserved flags to store other information about what was done to the data before being placed in Memcache.

An example is that I used a bit flag to represent that the data had been encrypted(mcrypt) or encoded(base64) before being inserted into Memcache. Several of the flags I was using broke upon my upgrade of the package because they were within the lowest two bytes that are now reserved for memcache internally.
 [2012-11-04 19:33 UTC] hradtke@php.net
Automatic comment from SVN on behalf of hradtke
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=328234
Log: Fix Bug #63272 - Explicitly reserve range of flags in php_memcache.h so application code can use
 [2012-11-04 19:34 UTC] hradtke@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: hradtke
 [2012-11-04 19:34 UTC] hradtke@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-11-04 19:35 UTC] hradtke@php.net
I added this to both branches. The values are different on each branch. I added 
some constants to make life easier for userland:
MEMCACHE_USER1
MEMCACHE_USER2
MEMCACHE_USER3
MEMCACHE_USER4

I will add these to the documentation as well.
 [2012-11-04 19:43 UTC] hradtke@php.net
Automatic comment from SVN on behalf of hradtke
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=328235
Log: Updated documentation for Pecl Bug #63272
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 13 21:01:31 2024 UTC