Apc_exist () does not exist?

I find it difficult to work with PHP APC. Here is my test code:

<form> <input type="text" name="apc"> <input type="submit"> </form> <?php apc_store('foo','FOO'); if (isset($_GET['apc'])) { apc_store($_GET['apc'],$_GET['apc']); } ?> <pre>CACHE INFO (USER): <?php print_r(apc_cache_info("user",false)); ?></pre> <pre>CACHE INFO: <?php print_r(apc_cache_info()); ?></pre> <pre>FOO: <?php print_r(apc_fetch("foo")); ?></pre> <pre>BAR: <?php print_r(apc_fetch("bar")); ?></pre> <pre><?php if (apc_exists("bar")) { ?>bar exists!<?php } else { ?>bar does not exist!<?php } ?></pre> <?php apc_clear_cache(); ?> 

In short: you fill out the form and the inserted value is saved in APC. The foo key is always saved. You can try to save the β€œbar” to see that apc_fetch() works with the newly added key.

What works fine:

  • apc_store()
  • apc_fetch()

What not:

  • apc_cache_info() (no matter what parameters I pass to the function) always prints an empty array, despite apc_fetch() receiving data successfully
  • apc_clear_cache() never clears the cache (the "line" is always displayed after input). This is true if I provide the "user" parameter or leave the function without parameters.
  • a call to apc_exists() results in a fatal error: a call to the undefined function apc_exists ()

In case this is useful: I am running Zend Server CE 5.6.0 (a new installation completed half an hour ago), with PHP 5.3.9. The same thing happened with the more antique version of Zend Server CE (starting PHP 5.3.5). I do not know what version of APC comes with Zend Server, phpinfo() only shows that APC is enabled. I am on a Windows machine (Windows 7 Professional, 32 bit).

So. What is wrong here? Problems with my code? Maybe Zend Server comes with an older version of APC that just bugs and / or doesn't support the features I'm trying to use? Any clues?

[EDIT]

Inspired by the hints provided by @Hannes, I changed the code by adding:

 <?php if (!function_exists('apc_exists') { function apc_exists($key) { return (boolean)apc_fetch($key); } } ?> 

Since the error does not occur, the code continues to the next line and the cache is cleared OK. This was probably due to the fact that it was not cleaned in the first place.

However, apc_cache_info() returns nothing ...

+4
source share
1 answer
  • apc_exists is available for PECL apc> = 3.1.4 http://www.php.net/manual/en/function.apc-exists.php , so your version of APC will turn out to be more doubtful, but its basically just a logical wraper in any case, a simple shoud function basically does the same thing:

    function user_apc_exists ($ key) {return (bool) apc_fetch ($ key); }

  • in both cases, your didint provides information for which the cache is used, your probaby wants the user:

     apc_clear_cache('user'); apc_cache_info('user); 

http://www.php.net/manual/en/function.apc-clear-cache.php

http://www.php.net/manual/en/function.apc-cache-info.php

+10
source

Source: https://habr.com/ru/post/1394564/


All Articles