Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make APC (PHP Cache) work?

I've read about APC that it speeds up multiple php file sites. So I have this particular project in PHP with many files and i discover that require_once and parsing only class definitions (without executing them) takes most time.

So I've installed APC on my CentOS 5 server. I moved apc.php to my webserver and it displays

Hits: 1 (50.0%)
Misses: 1 (50.0%)

Cached Files    1 (281.1 KBytes)

And I can go to website and change subpages and so on, and apc.php still shows only one cached file ??

And in phpinfo() it shows that:

APC Support enabled

I don't know what to do. Is APC working (like phpinfo() sais) or is it not? Only one cached file is not much after browsing some pages on my website.

And further more how to diagnose errors and make sure that APC works? I've browsed

apc.mmap_file_mask /tmp/apc.QnLqNf /tmp/apc.QnLqNf

Directory /tmp but I don't have any files of apc there like it's stated in phpinfo should occur.

Please help me check if APC is working and if not, what can be a problem.

like image 447
Tom Smykowski Avatar asked Sep 30 '09 00:09

Tom Smykowski


2 Answers

APC can be used in two ways:

  1. As an opcode cache. You have support enabled so this is working; and
  2. As a general cache. You have to explicitly use the API for this.

(1) is the main benefit. It reduces time for script execution by storing the opcode results of "compiling" scripts.

As for it working, from the installation instructions:

Note: On Windows, APC needs a temp path to exist, and be writable by the web server. It checks TMP, TEMP, USERPROFILE environment variables in that order and finally tries the WINDOWS directory if none of those are set.

So you shouldn't need it (or see any activity) on CentOS.

That being said, require/include are better than require_once/include_once/autoload but it should only matter if you are doing that with hundreds of files.

like image 90
cletus Avatar answered Sep 20 '22 04:09

cletus


Is your site basically one PHP file that then includes or requires other files? That may register as just a single file. Also, as far as I know, conditional include/require logic may not cache as expected though that may just be hearsay!

like image 33
Joanne C Avatar answered Sep 22 '22 04:09

Joanne C