elme — 2011-08-29T21:12:01-04:00 — #1
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?
immerse — 2011-08-30T03:24:50-04:00 — #2
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.
elme — 2011-08-30T04:00:15-04:00 — #3
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.
immerse — 2011-08-30T08:26:14-04:00 — #4
$count = apc_fetch('test_counter', $success);
$count = 0;
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?
elme — 2011-08-30T09:31:01-04:00 — #5
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.
r2d2 — 2011-08-30T11:13:29-04:00 — #6
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?
elme — 2011-08-30T17:53:38-04:00 — #7
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.
elme — 2011-08-30T18:25:30-04:00 — #8
it won't let me edit, forgot about the second part of the first image
immerse — 2011-08-31T02:54:42-04:00 — #9
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?
r2d2 — 2011-08-31T03:56:59-04:00 — #10
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?
elme — 2011-08-31T06:59:14-04:00 — #11
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.
r2d2 — 2011-08-31T07:02:29-04:00 — #12
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.
elme — 2011-08-31T08:28:48-04:00 — #13
nothing is added, you can see it here (user:apc pass:12345)
APC INFO (server1.shavek.com) (220.127.116.11)
and the code that Immerse posted over here
immerse — 2011-08-31T08:39:02-04:00 — #14
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.
anthonysterling — 2011-08-31T09:00:28-04:00 — #15
Great post Alex, very interesting...
r2d2 — 2011-08-31T09:08:42-04:00 — #16
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?
immerse — 2011-08-31T09:18:47-04:00 — #17
Or memcache, even. That's a totally separate bit of software that doesn't care how PHP accesses it.
anthonysterling — 2011-08-31T09:38:12-04:00 — #18
I'd certainly be leaning towards memcache (cached values as opposed to code) in this situation, good thread.
elme — 2011-08-31T10:04:04-04:00 — #19
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.