A question about APC

I’ve installed APC but it only keeps cache for current process so it doesn’t retrieve the data when i enter the page again.
I’ve been trying to google it but there’s too much information about it.
can someone give me a simple explanation about why it doesn’t work, how it should and how to make it work?

What do you mean with ‘current process’?

What TTL have you put on the caches?

Can you post some code of what you’re trying to do? That way we can see what might be going wrong.

i don’t put TTL in order to keep it in cache until i manually remove it, but i’ve also tried setting TTL and it still didn’t work.
there’s no code to post because I am just trying to store a variable on one page using
apc_store and it will output the right result when i apc_fetch within the same script.
but after i reload the page, it’s no longer in cache so
apc_fetch returns an empty result.


<?php

$count = apc_fetch('test_counter', $success);
if(!$success) {
    $count = 0;
}

$count++;

apc_store('test_counter', $count);

echo "\\$count is currently set to $count";

?>

Can you try the script above? Save it as a PHP file and then access it through your browser. Press F5 a couple of times. Does $count increase at all? Or does it stay at 0?

Also, how is your error_reporting level set?

It returns ‘1’ every time.
I’ve already tested it a lot, APC functions do work, the problem is,
it only save cache for current process, if i reload the page, the cache is cleared.

Can you copy in here what is says about apc in your phpinfo()?

Also, have you setup the apc.php info script? It should be in the apc archive you downloaded. Copy it to your Web server document root. Then, open it in a text editor and set the administrator password (you’ll find it near the top of the script). What does this say about user cache entries?

I am hosted on a managed VPS so they installed it for me (it’s managed so i rather let them install things i never did before)

Here’s the phpinfo

and about apc.php, here’s where it’s located in the server, didn’t really understand where do i have to put it.

I copied it into my root website folder and changed the password but it still doesn’t work.

it won’t let me edit, forgot about the second part of the first image

OK, this is kinda weird.

Can you ask your host (maybe you already know) how PHP is installed? As a sapi module? Or through (fast-)CGI?

You should just be able to visit in your web browser, eg. http://www.myrootdomain.com/apc.php

When you say it doesn't work, what happens when you visit it in your browser?

Immerse, phpinfo says "Server API : CGI " if that helps.

r2d2, the apc.php file works, but it didn’t help solving the problem, setting the password only allows me to login that page.

When you login, what does it show in User Cache Entries? You would expect to see a list of the entries that you’ve added.

nothing is added, you can see it here (user:apc pass:12345)
APC INFO (server1.shavek.com) (109.73.167.74)
and the code that Immerse posted over here
http://shavek.com/test.php

OK, I don’t know much about how CGI works, but isn’t it so that every request spawns a new CGI ‘process’ which is terminated at the end of the request?

In that case, I don’t think APC makes much sense, as the process is killed at the end of the request, which also terminates the APC cache.

When using APC is an Apache module, the APC cache is kept intact so long as the Apache process runs, meaning that data can be shared across requests.

I did find this article which might help a bit, but it looks like a lot of work, and it’s possibly very outdated: FastCGI with a PHP APC Opcode Cache | Brandon's Blog

Lastly, I’m not sure about the workings of CGI, so it’s quite possible that what I’ve just written above is total claptrap. :smiley:

Off Topic:

Great post Alex, very interesting…

It would seem to make sense that APC use in FastCGI would be very different to use in PHP as a module. Found this article (Why APC sucks (and should be pulled from PECL)) which is a bit older than your link Immerse, which suggests XCache might be more suitable for FastCGI use. A search on google for FastCGI and XCache shows lots re using Lighttpd and NGinX though, rather than Apache.

Looking at your apc.php, you can see that it isn’t working as intended at all - so in this case using APC will probably be slowing you down - i.e. extra time caching the opcodes, that will then be cleared.

Is there a reason you’re using CGI, not running PHP as a module? You have a VPS, so you don’t need to worry about other users accessing your cache as on shared hosting?

Or memcache, even. That’s a totally separate bit of software that doesn’t care how PHP accesses it.

I’d certainly be leaning towards memcache (cached values as opposed to code) in this situation, good thread. :slight_smile:

I’ve never dealt with installing PHP and everything associated with it on a linux server, that’s why I let my host install it, sicne I wanted everything to be secure and configured properly and they installed it under CGI.

My current application handles a big amount http requests and queries per second so to lighten the cpu usage, I’m looking to store some information in the cache.
(also trying to convert the app to use socket.io instead of handling ajax requests each second, but that’s already a different thing)

after reading your responses I’ve been reading a bit about cgi/apache module and the differences about them, and it also made me figure that installing PHP under apache module will reduce my CPU usage when I’m using that much http requests.

I’ll keep reading about xcache/memcache with CGI and see if i should use one of those or reconfigure php to use apache module and stick with APC.

thank you.