在共享主机的情况下如何为不同的 URL 分离 APC 缓存?

How to seperate APC cache for different URLs in case of shared hosting?

我在共享主机上使用 doctrine2 的 APC 缓存。

我托管了同一个项目的多个实例,但版本不同。所以我不希望他们共享相同的缓存。

例如,我有以下托管 URL:

http://phpdemo.******.com:9040/ilook/qa
http://phpdemo.******.com:9040/ilook/android
http://phpdemo.******.com:9040/ilook/dev
http://phpdemo.******.com:9040/ilook/client

Is there any way to differentiate the cache for them?

php.ini 设置:

[APC]
apc.shm_size = '128M'
apc.enabled=1
apc.shm_segments=1
apc.num_files_hint=0
apc.user_entries_hint=0
apc.ttl=0
apc.user_ttl=7200
apc.gc_ttl=3600
apc.stat=1
apc.enable_cli=0
apc.file_update_protection=2
apc.max_file_size=2M
apc.cache_by_default=1
apc.use_request_time=1
apc.slam_defense=0
apc.stat_ctime=0
apc.canonicalize=1
apc.write_lock=1
apc.report_autofilter=0
apc.rfc1867=0
apc.rfc1867_prefix =upload_
apc.rfc1867_name=APC_UPLOAD_PROGRESS
apc.rfc1867_freq=0
apc.rfc1867_ttl=3600
apc.lazy_classes=0
apc.lazy_functions=0

因为我使用的是 ZF1 + Doctrine2,所以下面是我在 bootstrap.php 文件中使用的配置行。

$config = new \Doctrine\ORM\Configuration();

$cache = new \Doctrine\Common\Cache\ApcCache;

$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$config->setResultCacheImpl($cache);

关于您的 bootstrap.php,您应该能够为每个项目的缓存定义不同的命名空间,例如:

$config = new \Doctrine\ORM\Configuration();

$cache = new \Doctrine\Common\Cache\ApcCache;

// define the cache for this project only
$cache->setNamespace('project_name');

$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$config->setResultCacheImpl($cache);