apc_store isn't working between requests
Asked Answered
M

3

7
$bar = 'BAR';
apc_store('foo', $bar);
var_dump(apc_fetch('foo'));

Within one request this work.

Now If i try to do a var_dump(apc_fetch('foo')); on another request it prints:

bool(false)

Any help?

I am on gentoo with PHP 5.2, APC-3.1.9

Here what phpinfo() knows about APC:

APC Support enabled
Version 3.1.9
APC Debugging   Disabled
MMAP Support    Enabled
MMAP File Mask  no value
Locking type    pthread mutex Locks
Serialization Support   php
Revision    $Revision: 308812 $
Build Date  May 27 2011 13:14:20

Directive   Local Value Master Value
apc.cache_by_default    On  On
apc.canonicalize    On  On
apc.coredump_unmap  Off Off
apc.enable_cli  Off Off
apc.enabled On  On
apc.file_md5    Off Off
apc.file_update_protection  2   2
apc.filters no value    no value
apc.gc_ttl  3600    3600
apc.include_once_override   Off Off
apc.lazy_classes    Off Off
apc.lazy_functions  Off Off
apc.max_file_size   1M  1M
apc.mmap_file_mask  no value    no value
apc.num_files_hint  1000    1000
apc.preload_path    no value    no value
apc.report_autofilter   Off Off
apc.rfc1867 Off Off
apc.rfc1867_freq    0   0
apc.rfc1867_name    APC_UPLOAD_PROGRESS APC_UPLOAD_PROGRESS
apc.rfc1867_prefix  upload_ upload_
apc.rfc1867_ttl 3600    3600
apc.serializer  default default
apc.shm_segments    1   1
apc.shm_size    32M 32M
apc.slam_defense    On  On
apc.stat    On  On
apc.stat_ctime  Off Off
apc.ttl 0   0
apc.use_request_time    On  On
apc.user_entries_hint   4096    4096
apc.user_ttl    0   0
apc.write_lock  On  On

If you need other infos please tell me

Here is how I installed it: https://serverfault.com/questions/274261/failed-installing-apc

I noticed one thing: In the phpinfo' Configure command i didn't find apc

'./configure' '--disable-cli' '--disable-discard-path' '--disable-force-cgi-redirect' '--prefix=/usr/local/php5' '--with-config-file-path=/usr/local/lib/php5' '--with-pear=/usr/share/php5' '--enable-exif' '--enable-ftp' '--enable-bcmath' '--enable-calendar' '--with-gd' '--enable-gd-native-ttf' '--with-freetype-dir' '--with-gettext' '--with-zlib-dir' '--with-imap' '--with-imap-ssl' '--with-png-dir=/usr' '--with-jpeg-dir=/usr' '--with-xpm-dir=/usr' '--with-openssl' '--with-kerberos' '--enable-sysvsem' '--enable-sysvshm' '--with-mcrypt' '--with-iconv' '--enable-mbstring=all' '--enable-mbregex' '--with-mysql=/usr' '--with-mysqli' '--with-curl' '--with-xsl'

Mourning answered 27/5, 2011 at 12:56 Comment(1)
@aj: i downloade the lastest: APC-3.1.9Mourning
L
6

Probably you are running PHP over CGI (instead of FastCGI which you ought to use) - see my answer in another question why APC doesn't work if PHP is running over CGI.

Lanky answered 31/5, 2011 at 18:16 Comment(1)
@yes123: Which webserver are you using? I'm using nginx, so FastCGI is pretty much the "normal" way of using PHP with it. If you're using Apache you would probably use mod_php instead (APC works on mod_php, too). But I never really used Apache so I can't tell you how to configure that ^^Lanky
N
0

Your default ttl (apc.ttl) is 0 seconds, that is strange - please try to specify a ttl (in seconds) when storing the value:

apc_store('foo', $bar, 60);
Noonday answered 27/5, 2011 at 13:26 Comment(0)
A
0

Content of php.ini

apc.enabled="1"
apc.shm_segments="1"
apc.shm_size="128M"
apc.ttl="7200"
apc.user_ttl="7200"
apc.file_update_protection="3"
apc.cache_by_default="0"
apc.max_file_size="1M"
apc.stat="0"
apc.write_lock="1"
apc.report_autofilter="0"
apc.include_once_override="0"
apc.localcache="1"
apc.localcache.size="1024"
apc.coredump_unmap="0"
; Optional, Comment out them later on
apc.num_files_hint="5000"
apc.user_entries_hint="5000"
apc.gc_ttl="3600"
apc.stat_ctime="0"

Content of apctest.php

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

Result of apctest.php

string 'BAR' (length=3)

Content of apctest2.php

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

Result of apctest2.php

string 'BAR' (length=3)

apc.php shows under "Users Cache Entries"

User Entry Label    Hits    Size    Last accessed   Last modified   Created at  Timeout Deleted at
foo 4   656 31.05.2011 12:12:22 31.05.2011 12:05:33 31.05.2011 12:05:33 None    [Delete Now]

Software versions:

PHP Version 5.3.6
Server Version: Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 SVN/1.6.9 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_fcgid/2.3.5 mod_perl/2.0.4 Perl/v5.8.8
OS: CENTOS 5.6 x86_64 standard
Archfiend answered 31/5, 2011 at 9:19 Comment(14)
@RR: is that normal in my php.ini these settings are not present? Where should I put edit this setting?Mourning
I have them only in my php.ini and not on other place. Btw, I presume you are aware that APC flush saved ids on apache restart too, right?Archfiend
I had to tell, because I didn't know it in the beginning :PArchfiend
ok edited php.ini and rebooted apache. Still apc_fetch doesn't workMourning
edit apc.cache_by_default off I just remember that this option cause me some problems in the beginning.Archfiend
@RRStoyanov: you mean put it to On?Mourning
@rr: I have putted it to On rebooted and nothing changedMourning
@rr: could it be because there isn't any apc in the configure commnad? Read first postMourning
OK. I was with 3.1.7 and had the problem you described. I update to 3.1.9 and it's not works. First request set it, other request show it correct now. I will update my post with my php.ini settings for the APC. I create apctest.php with your content and apctest2.php with just fetch and I see correct results. Under apc.php I also see the setted cache. Will post also my software versions on the updated post.Archfiend
I have the same problem. I have 2 file, first file does a apc_store, second file does a apc_fetch but apc_fetch doesn't work in second fileMourning
I did everything! apctest2.php shows: bool(false). Under "USER CACHE ENTRIES of apc.php" there is "NO DATA" DAMN GENTOOMourning
Sorry to hear that. Wanted to help, but no luck... Wish you luck trying to find a solution.Archfiend
I give another bounty on serverfault. I hope someone there can help me, because it could be some sort of installation problem I believe: serverfault.com/questions/274261/failed-installing-apcMourning
@yes123 did you check those links? #3954173 blog.chrisbaran.net/2009/02/19/… and maybe check this out too packages.gentoo.org/package/dev-php5/pecl-apc. Good luck.Archfiend

© 2022 - 2024 — McMap. All rights reserved.