Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#287 closed enhancement (fixed)

separated cache by vhost, with patch!

Reported by: mzhg Owned by: moo
Priority: major Milestone: 3.0.0
Component: cacher Version: 2.0.0
Keywords: Cc:
Application: PHP Version:
Other Exts: SAPI: Irrelevant
Probability: Blocked By:



Two month ago I've may some test around cache separation for vhost (under apache itk mainly) So here the patch !

!! it's working but not stable enough for prod !!

Maybe you can easily leverage on this patch to include the feature in xcache faster.

I currently use the userid (since I need the feature under apache-itk) to prefix all cache key.

Should be better to use a config variable (which must be settable in a vhost directive using php_admin_value)

The patch was against rev 902 at the time.

Thanks you.


Attachments (3)

xcache-itk_vhost.patch (6.0 KB) - added by mzhg 7 years ago.
version 4, added missing xcache_unset_by_prefix
xcache_vhost.patch (11.2 KB) - added by mzhg 7 years ago.
version 4 (good file .. really time to go to bed)
xcache_admin.png (17.4 KB) - added by mzhg 7 years ago.
Screenshot of admin

Download all attachments as: .zip

Change History (19)

comment:1 Changed 7 years ago by mzhg

  • Version changed from 2.0.1 to 2.0.0

comment:2 Changed 7 years ago by moo

  • Milestone changed from undecided to 3.0.0
  • Status changed from new to assigned

comment:3 Changed 7 years ago by moo

the patch rely on "uid", but may not always be the correct case. i'll have to re-implement it

comment:4 Changed 7 years ago by mzhg


Yes i am using the uid since i made the patch for apache-itk, which run each vhost under a specific user/group.

I'll try to take some time to remake a patch on the last version, using a prefix from the ini settings.

This was mainly a PoC, do you think this implementation is a good way to do it ?

comment:5 Changed 7 years ago by moo

no. ini setting is hard to maintain massive vhost supplier. consider using $_SERVERHTTP_HOST?, copy original value at request start handler to avoid using the one modified by script

comment:6 Changed 7 years ago by mzhg

I was thinking of a ini setting to be able to set it into the vhost directive using php_admin_value, which i can massively set with proper apache module.

Using the host is good since it's unique, but I think it's less flexible than a settings..

To be honest I was planning:

  • one ini setting to choose a "operating mode": uid/host/custom
  • one ini setting for the custom mode

The best of both world :)

comment:7 Changed 7 years ago by moo

yeah, that will do

comment:8 Changed 7 years ago by mzhg


I've just finished to remake a patch against rev 1141.

There two new INI settings:

  • Case xcache.var_prefix_mode = 0: Disabled
  • Case xcache.var_prefix_mode = 1:

The prefix can be the uid or gid
xcache.var_prefix_value = "uid"|"gid"

  • Case xcache.var_prefix_mode = 2:

The prefix can be any value of $_SERVER
xcache.var_prefix_value = [any SERVER key] !!case sensitive!!

xcache.var_prefix_value = "SERVER_NAME"
xcache.var_prefix_value = "HTTP_HOST"
xcache.var_prefix_value = "DOCUMENT_ROOT"

  • Case xcache.var_prefix_mode = 3:

The prefix is custom
xcache.var_prefix_value = [any string]

few things you need to check:

  • I use getuid() and getgid() but I haven't test #ifdef win32, need a workaround
  • You may need to check for memory leak, and some ugly code, since I am not a Zend developer, I am sure there is better way to do some of my code
  • Maybe a better check on INI settings


comment:9 Changed 7 years ago by mzhg

Oops, it seams I have forgot something related to the administration, deletion of var is broken... I am on it.

comment:10 Changed 7 years ago by mzhg

Finally! I've found my bug!


  • Fix a typo in htdocs/cacher/edit.php
  • Add a missing submit button in htdocs/cacher/sub/entrylist.tpl.php
  • Tried to implement all Unicode #Ifdef block, to be check!
  • Fix a bug which was updating the name variable with the prefix on client side

Time to sleep :)

Changed 7 years ago by mzhg

version 4, added missing xcache_unset_by_prefix

Changed 7 years ago by mzhg

version 4 (good file .. really time to go to bed)

comment:11 Changed 7 years ago by mzhg

Sorry about the multi files posting, I'm a little tired :)

The good one is "xcache_vhost.patch", you can discard the other one.

comment:12 Changed 7 years ago by moo


comment:13 Changed 7 years ago by moo

  • Resolution set to fixed
  • Status changed from assigned to closed

committed as [1146] for trunk

; mode:0, const string specified by xcache.var_namespace
; mode:1, $_SERVER[xcache.var_namespace]
; mode:2, uid or gid (specified by xcache.var_namespace)
xcache.var_namespace_mode =    0
xcache.var_namespace =        ""

comment:14 Changed 7 years ago by mzhg

Woo, you're fast!

I have updated and tested, there is two things in the administration which seams odd:

  1. variable visibility in administration

I have a first vhost using uid as namespace and a second vhost using a custom string
The first vhost is running the Administration, he can see his own variable (without namespace) but he can also see variables of the second vhost, with namespace.
This lead to privacy loss. Each administration must be constrains to their namespace, IMHO.

  1. there is a "\0" between the namespace and the variable name.

See attached screenshot.

Regarding the xcache_set_namespace API, how does it work ?
I must be sure the user can't alter his namespace.

Thanks you.


Changed 7 years ago by mzhg

Screenshot of admin

comment:15 Changed 7 years ago by moo

about \0: the \0 is intended to solve some stupid domain name introduce by some stupid country. e.g.: vs (while it should be, without \0 separator, xcache_set(".cn", 1) under "" is identical to xcache_set("", 1) under "". domain name is not the only problem. same applies if you have uid 1024 and 10241

about xcache_set_namespace: when user set namespace, it's a inner namespace under the current outer namespace. it's similar to hard ulimit vs soft ulimit. user can never break out of the outer namespace

about admin variable list: the current XCache admin page is designed for server administrator, not vhost owner

i haven't get enough time to test all use cases in namespace. any phpt is welcome

comment:16 Changed 7 years ago by mzhg

Very nice! Thanks you for the explanations.

Note: See TracTickets for help on using tickets.