PHP Doku:: Fetch a stored variable from the cache - function.apc-fetch.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDas Verhalten von PHP beeinflussenAlternativer PHP CacheAPC Funktionenapc_fetch

Ein Service von Reinhard Neidl - Webprogrammierung.

APC Funktionen

<<apc_exists

apc_inc>>

apc_fetch

(PECL apc >= 3.0.0)

apc_fetch Fetch a stored variable from the cache

Beschreibung

mixed apc_fetch ( mixed $key [, bool &$success ] )

Fetchs a stored variable from the cache.

Parameter-Liste

key

The key used to store the value (with apc_store()). If an array is passed then each element is fetched and returned.

success

Set to TRUE in success and FALSE in failure.

Rückgabewerte

The stored variable or array of variables on success; FALSE on failure

Beispiele

Beispiel #1 A apc_fetch() example

<?php
$bar 
'BAR';
apc_store('foo'$bar);
var_dump(apc_fetch('foo'));
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

string(3) "BAR"

Changelog

Version Beschreibung
3.0.17 The success parameter was added.

Siehe auch

  • apc_store() - Cache a variable in the data store
  • apc_delete() - Removes a stored variable from the cache
  • APCIterator


5 BenutzerBeiträge:
- Beiträge aktualisieren...
myfirstnameattimronayne.com
18.05.2010 14:46
Another reason you might be getting null back from apc_fetch when using apc.rfc1867 is if you have only turned this option on using php_admin_value for a virtual host. It needs to be turned on globally in php.ini to work.
chris at active9 dot com
7.07.2009 9:00
Anyone who has enabled apc.rfc1867 for a file upload progress bar. Please note that if you are not getting any results back or a Null() data set. Then set apc.rfc1867_freq to 10k or 100k or whatever you see fit like this.

apc.rfc1867_freq = 10k

In your php.ini.

Hope this helps some of you who were getting blank data results. It seems the 0 default setting will not work on some machines. Hope this helps!
marcus at synchromedia dot co dot uk
3.05.2008 18:54
Just to clarify the multi-get capability, the result is returned as an array with cache keys as the array keys. Any missing values re not returned, for example:

<?php
apc_delete
('test1');
apc_delete('test2');
apc_add('test1', 'test1');
$cached = apc_fetch(array('test1', 'test2'));
var_dump($cached);
?>

gives

array(1) {
  ["test1"]=>
  string(5) "test1"
}

If no keys are found, you get an empty array.
nospam dot list at unclassified dot de
21.11.2007 0:06
This function is often cited related to file upload tracking with PHP 5.2. So I thought this is a good place to put a warning.

If you setup PHP with FastCGI, you'll probably run into trouble using this function to get any information about a running upload. At least in my case, every HTTP request is handled by a different PHP process. I could track it with the getmypid() function, which returned a different value upon every request, but only from a limited set. Also, apc_cache_info() gave me all upload_* entries that were created in that process. So when the upload was initially catched by one PHP process, all progress updates must be fetched from the same process, too, because APC cache information does not seem to be shared across multiple processes handling that domain/virtual host. But that's impossible to tell because PHP has its own load management and serves every request by an arbitrary process.

So in short: When using FastCGI and multiple PHP processes (recommended for performance reasons), you cannot use APC upload tracking. You'll only get a status update every few requests.
thijsterlouw at gmail dot com_remove_this
28.02.2007 10:31
As of version 3.0.13 APC (released 2007-02-24) you can perform multiple key fetches with apc_fetch. Very useful to further optimize your application!
APC changelog:
http://pecl.php.net/package-changelog.php?package=APC

example:

<?php
apc_store
('key1', 'value1');
apc_store('key2', 'value2');

$keys = array('key1','key2');
$result = apc_fetch($keys);  //fetch multiple keys at once!

var_dump($result);
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)