2
  • APC 版本:3.1.9。
  • PHP版本:5.2.17
  • 我使用 Litespeed
  • 默认 PHP:5
  • PHP4 SAPI: cgi
  • PHP5 SAPI:dso
  • SUEXEC:启用

我创建了 2 个文件。第一个文件,设置 apc var :

<?php
$bar = 'BAR';
apc_store('foo_test', $bar);
echo 'stored';
?>

第二个文件,尝试获取 apc var :

<?php
var_dump(apc_fetch('foo_test'));
?>

我访问了第一个文件,一切都很好。我打开第二个文件,我刷新了几次,通常(几乎 90%),它返回 false。并且很少返回正确的响应。

这是我的 APC 设置。

apc.cache_by_default    1
apc.canonicalize    1
apc.coredump_unmap  0
apc.enable_cli  1
apc.enabled 1
apc.file_md5    0
apc.file_update_protection  2
apc.filters 
apc.gc_ttl  3600
apc.include_once_override   0
apc.lazy_classes    0
apc.lazy_functions  0
apc.max_file_size   20M
apc.mmap_file_mask  
apc.num_files_hint  1000
apc.preload_path    
apc.report_autofilter   0
apc.rfc1867 0
apc.rfc1867_freq    0
apc.rfc1867_name    APC_UPLOAD_PROGRESS
apc.rfc1867_prefix  upload_
apc.rfc1867_ttl 3600
apc.serializer  default
apc.shm_segments    1
apc.shm_size    512M
apc.slam_defense    1
apc.stat    0
apc.stat_ctime  0
apc.ttl 0
apc.use_request_time    1
apc.user_entries_hint   4096
apc.user_ttl    7200
apc.write_lock  1
4

1 回答 1

2

我的猜测是 Litespeed 正在使用 FastCGI 运行 PHP。所以它产生了一些子进程,然后在它们之间分派请求。问题是APC可能将数据存储在堆内存中(而不是在共享内存中),因此每个 FastCGI 实例都有自己的 APC 数据。一个实例中的数据在其他实例中将不可见。您在实例#1 中设置数据,但随后您的获取请求转到实例#2、实例#3...,然后您得到FALSE。当您点击实例 #1 时,您将收到保存的值。

编辑:使用--disable-apc-mmap(禁用 mmap 支持并改用 IPC shm)编译 APC 模块应该可以解决问题。

于 2012-04-27T14:47:49.097 回答