13

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.

Tom Smykowski
  • 25,487
  • 54
  • 159
  • 236
  • What's your APC config? Specifically check for: apc.include_once_override=1 Which fixes a problem with APC and the standard include/reuire code in php – Neel Sep 30 '09 at 10:11
  • What kind of PHP-SAPI and Server are you using? Apache + mod_php, Apache + mod_fcgi / mod_fastcgi or some Lighttpd + fastcgi? – Benjamin Cremer Oct 04 '09 at 17:52
  • I'm having the same problem. Apache + mod_php, and apc.php is reporting only 1 cached file (which I suspect is the apc.php file itself). Has there been any revelation to this yet? – Chris Tonkinson Dec 22 '10 at 18:28
  • I am having the same issue, in addition, when I try to run apc_compile_file('somefile.php') (I did this for debugging purposes), it returns false, meaning it can't compile a file at all. Did we miss some compiler directive while compiling the extension? – Pelle Jan 05 '11 at 17:31
  • @DudeSolutions Glad you had laughts, but in fact it was not about only 2 files. – Tom Smykowski Dec 19 '12 at 12:02
  • @tomaszs Ohhh, ok! My apologies for being so critical:) – FredTheWebGuy Dec 19 '12 at 17:11

6 Answers6

8

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.

cletus
  • 616,129
  • 168
  • 910
  • 942
  • 5
    Ok, I understand. But is there any way to test if it really works? As I metioned APC.php shows only one hit and miss and that looks like it does not work. – Tom Smykowski Sep 30 '09 at 08:24
  • 2
    I second this. Is there any evidence (apart from the speed increase) that can tell you it's actually working? – Pelle Jan 05 '11 at 17:30
  • 2
    I am in same dilemma, apc.php shows only one file in cache which is apc.php. I am confused :( – Kumar Dec 15 '11 at 08:07
2

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!

Joanne C
  • 1,115
  • 6
  • 10
  • I don't have conditionals. I have 4 files that include 3 library files. I would like to make sure APC works, because APC.PHP does not idicate it. – Tom Smykowski Sep 30 '09 at 08:25
1

Did you check thr log files? take a look at /var/log/apache2/error.log or however its named under your distribution.

Also, try to make 2-3 php files, point thebrowser at them, and then check how many php files are cached by the APC cache..

Not sure about APC, but i'd recommend Eaccelerator (http://eaccelerator.net/). I've tested it some time ago and really made a difference.

Quamis
  • 10,924
  • 12
  • 50
  • 66
1

APC actually doesnt share cache between proceses. Try to configure your PHP-Process to fork Childs and let the Master PHP-Process stay running.

See: How to share APC cache between several PHP processes when running under FastCGI?

Community
  • 1
  • 1
Benjamin Cremer
  • 4,842
  • 1
  • 24
  • 30
1

In the APC 3.1.5dev branch, a new option was introduced allowing you to disable the opcode cache. It appears to be turned off by default.

Try adding this to your APC config file:

apc.enable_opcode_cache=1
smokris
  • 11,740
  • 2
  • 39
  • 59
0

http://www.litespeedtech.com/support/forum/showthread.php?t=3761

"APC does not work well with PHP suEXEC as each PHP process will use its own cache memory, not shared.

You should try eAccelerator + /dev/shm if you need to use PHP suEXEC."

well got same problem, it seems PHP suEXEC + APC is problem

Ünsal Korkmaz
  • 224
  • 4
  • 17