php-apcu (CGI/FastCGI) apc_fetch always return fal

2019-08-22 17:31发布

问题:

When using the php-apcu (https://github.com/krakjoe/apcu) extension (not apc) in a php CGI environment the stored data fromapc_store are empty.

Anyone has experiences on how to solve this issue?

Example PHP File: test-apc.php

<?php
$k = 'test';
if(isset($_GET['get'])) {
    $result = apc_fetch($k);
    echo "Read entry '$k': $result";
} else if(isset($_GET['clear'])) {
    echo "Clear entry '$k'";
    apc_clear_cache('user');
} else {
    apc_store($k, "HelloWord");
    echo "Write entry '$k' set";
}
print_r(apc_cache_info('user'));
?>

Steps to reproduce:

  1. Open http://server/test-apc.php to call apc_store
  2. Open http://server/test-apc.php?get to receive stored data using apc_fetch

BTW: apc_cache_info('user') shows it properly with first request, second is empty

Relevant packages (OS: Debian 3.2.63):

  • Apache 2.2.22 (mpm-prefork, suexec-custom, wrapper)
  • php5.5 as CGI
  • php5-apcu 4.0.7
  • (and dependencies)

回答1:

The module php-apcu is not fully compatible with CGI/fcgid.

Possible reason: CGI/fcgid executes the php interpreter as a new instance on every HTTP REQUEST. So apcu/apc cannot recover the user caches.

The module mod-fastcgi (non-free package for Debian) together with php5-fpm can provide remedy. Its uses a different technique to manage processes.


http://php-fpm.org/wiki/ (down atm - 2015-09-02)



标签: php apache apc