I've got to be missing something obvious. My APC is installed correctly and showing up in phpinfo() just fine. I'm currently running php 5.4.20 with APC 3.1.13 on apache. It is a cpanel install so keep that in mind as well.
The main problem is that the cache is working, but only for the duration of the page load. if I run
<?php
apc_store('foo', 'bar');
echo apc_fetch('foo');
?>
It will echo out the variable, but if I comment out apc_store and run the code again, nothing shows up and var_dump shows boolean(false);
I've tried this code also in case I was doing something dumb, and this does not work also. It always shows "str not found from cache...saving"
// Check if str found from cache
if (apc_exists('str')) {
// Print str from cache
echo "str from cache: ", apc_fetch('str'), "<br />";
// Clear cache
apc_clear_cache('user');
// Try to fetch str again
echo "str from cache, after user cache is cleared: ", "<br />";
var_dump(apc_fetch('str'));
}
else {
// Save str to cache and set ttl 120 seconds
echo 'str not found from cache...saving', "<br />";
$str = "This is just test";
apc_store('str', $str, 120);
}
My apc config is as follows...
apc
APC Support => disabled
Version => 3.1.13
APC Debugging => Disabled
MMAP Support => Enabled
MMAP File Mask =>
Locking type => pthread read/write Locks
Serialization Support => broken
Revision => $Revision: 327136 $
Build Date => Oct 17 2013 16:47:57
Directive => Local Value => Master Value
apc.cache_by_default => Off => Off
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 => 512 => 512
apc.shm_strings_buffer => 4M => 4M
apc.slam_defense => Off => Off
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
I must be missing something obvious..... any help is appreciated. TIA
EDIT
So I checked to see if it apc was working properly on the prod server that has apc already installed on it. It in fact is working as it should be. So I ran php_sapi_name() and on the prod server it is apache2handler and on the dev server (the one I'm currently working with), it is using cgi-fcgi, which is probably the cause for the problem. Since I'm using cPanel I should be able to simply change the PHP "Handler" from suPHP to maybe DSO and it should work after that. The prod server doesn't use cpanel, just good old fashion....er.....non-cPanel stuff to make it work.
I found this thread that answered my question. The root problem was that I was running under CGI-FCGI when I needed be be under DSO/mod_php to run APC properly. Changing that on Cpanel was a beast because the apc.so extension caused the part when you change the php handler to fail....yar.