php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65622 Cache TTL does not expire during request
Submitted: 2013-09-05 12:39 UTC Modified: 2013-09-06 14:39 UTC
From: stanislav dot khromov at gmail dot com Assigned:
Status: Not a bug Package: APC (PECL)
PHP Version: 5.4.19 OS: CentOS
Private report: No CVE-ID: None
 [2013-09-05 12:39 UTC] stanislav dot khromov at gmail dot com
Description:
------------
APC 3.1.13, Apache

Cache TTL does not expire during a request.

Check script. It stores a variable for 5 seconds and then sleeps. But even after 5 seconds has gone and the TTL has expired the variable is still returned.

Test script:
---------------
<?php
apc_store('foo', 'bar', 5);

var_dump(apc_fetch('foo'));
sleep(2);
echo '<br/>';

var_dump(apc_fetch('foo')) . '<br/>';
sleep(2);
echo '<br/>';

var_dump(apc_fetch('foo')) . '<br/>';
sleep(2);
echo '<br/>';

var_dump(apc_fetch('foo')) . '<br/>';
sleep(2);
echo '<br/>';

Expected result:
----------------
string(3) "bar"
string(3) "bar"
bool(false)
bool(false) 


Actual result:
--------------
string(3) "bar"
string(3) "bar"
string(3) "bar"
string(3) "bar" 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-05 20:52 UTC] aurelien dot lequoy at gmail dot com
apc.php

<?php

error_reporting(-1);
ini_set('display_errors', '1');

$bar = "EEE";


apc_store ('foo', $bar, 40);

var_dump(apc_fetch('foo'));
sleep(20);

var_dump(apc_fetch('foo'));
sleep(20);

$gg = shell_exec("php apc2.php");

echo $gg;

apc.php
<?php
var_dump(apc_fetch('foo'));



php apc.php
string(3) "EEE"
string(3) "EEE"
bool(false)


result is good

var are loaded at start or after declaration of apc_store. to see cash down you 
to exec an other script, else it will not disappear.
 [2013-09-05 21:32 UTC] stanislav dot khromov at gmail dot com
Yes, it's true that executing the script in another thread will check the TTL on script execution, but the TTL is still not respected while the current request is running. This is an issue if you have a long-running script.

> var are loaded at start or after declaration of apc_store

Where is this behaviour documented?
 [2013-09-06 12:39 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2013-09-06 12:39 UTC] rasmus@php.net
It doesn't make a whole lot of sense to read a cache entry from the same request 
that you wrote it from. Why not just keep it in local storage then? APC is 
optimized for cross-request caching, so if you want same-request caching like 
this you will have to cache your own TTL value and check it yourself.
 [2013-09-06 14:39 UTC] stanislav dot khromov at gmail dot com
Thanks for pitching in Rasmus.

I am writing a cache library and wrote a unit test that assumes cache entries expire after the TTL, even during the same requests. Since APC failed the tests I decided to file a bug report.

It makes sense what you are saying. It would be nice to have a footnote somewhere in the documentation regarding this though.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 06:01:29 2024 UTC