Alternative PHP Cache ( APC )
This accelerator does not perform well at all under Apache 2.2.0. Just running one of my site used
nearly all the memory (30M max).
The segment feature doesn't really work on Windows, so you're limited to 30M.
Update02/2006: Under Apache 2.0.55 and 2.2.2 it seems to perform normally.
eAccelerator seems faster then APC. But if you are running multiple instances of Apache on the same server you will appreciate a second caching tool for PHP. I use both APC and eAccelerator with production sites. APC seems to be getting better just in the last 3 months (since 01/2006).
Note: This accelerator might get better, in the near future, since some of the PHP developers appear to also be involved with APC.
Windows binaries download:
http://pecl4win.php.net/ext.php/php_apc.dll
Sitebuddy
APC Windows Binaries for PHP 5.
Sitebuddy
APC Windows Binaries for PHP 4.
Download Source:
http://pecl.php.net/package/APC
Doc:
http://us2.php.net/apc
Install is very easy:
1) Download the APC dll (php_apc.dll) see previous link "Windows binaries download".
2) Copy this DLL to your php extensions folder.
3) Enable the this extension in your php.ini by "un-commenting" or adding the
line:
extension=php_apc.dll
4) Add APC configuration directive to your php.ini, like:
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 64
apc.optimization = 0
apc.num_files_hint = 1000
apc.ttl = 0
apc.gc_ttl = 3600
apc.cache_by_default = On
apc.slam_defense = 0
apc.file_update_protection = 2
apc.enable_cli = 0
apc.stat=0
; If you experience intermittent blank pages don't set apc.stat=0
Following is the official description of the configuration directives.
5) Restart your web server.
------------------Official description of the APC configuration directives
--------------------------------------------------
apc.enabled This can be set to 0 to disable APC. This is primarily useful
when APC is statically compiled into PHP, since there is no other way to disable
it (when compiled as a DSO, the zend_extension line can just be commented-out).
(Default: 1)
apc.shm_segments The number of shared memory segments to allocate for the
compiler cache. If APC is running out of shared memory but you have already set
apc.shm_size as high as your system allows, you can try raising this value.
(Default: 1)
apc.shm_size The size of each shared memory segment in MB. By default,
some systems (including most BSD variants) have very low limits on the size of a
shared memory segment.
(Default: 30)
apc.optimization The optimization level. Zero disables the optimizer, and
higher values use more aggressive optimizations. Expect very modest speed
improvements. This is experimental.
(Default: 0)
apc.num_files_hint A "hint" about the number of distinct source files
that will be included or requested on your web server. Set to zero or omit if
you're not sure; this setting is mainly useful for sites that have many
thousands of source files.
(Default: 1000)
apc.user_entries_hint Just like num_files_hint, a "hint" about the number
of distinct user cache variables to store. Set to zero or omit if you're
not sure;
(Default: 100)
apc.ttl The number of seconds a cache entry is allowed to idle in a slot
in case this cache entry slot is needed by another entry. Leaving this at
zero means that your cache could potentially fill up with stale entries while
newer entries won't be cached.
(Default: 0)
apc.user_ttl The number of seconds a user cache entry is allowed to idle
in a slot in case this cache entry slot is needed by another entry. Leaving this
at zero means that your cache could potentially fill up with stale entries while
newer entries won't be cached.
(Default: 0)
apc.gc_ttl The number of seconds that a cache entry may remain on the
garbage-collection list. This value provides a failsafe in the event that a
server process dies while executing a cached source file; if that source file is
modified, the memory allocated for the old version will not be reclaimed until
this TTL reached. Set to zero to disable this feature.
(Default: 3600)
apc.cache_by_default On by default, but can be set to off and used in
conjunction with positive apc.filters so that files are only cached if matched
by a positive filter.
(Default: On)
apc.filters A comma-separated list of POSIX extended regular expressions.
If any pattern matches the source filename, the file will not be cached. Note
that the filename used for matching is the one passed to include/require, not
the absolute path. If the first character of the expression is a + then the
expression will be additive in the sense that any files matched by the
expression will be cached, and if the first character is a - then anything
matched will not be cached. The - case is the default, so it can be left off.
(Default: "")
apc.mmap_file_mask If compiled with MMAP support by using --enable-mmap
this is the mktemp-style file_mask to pass to the mmap module for determing
whether your mmap'ed memory region is going to be file-backed or shared memory
backed. For straight file-backed mmap, set it to something like /tmp/apc.XXXXXX
(exactly 6 X's). To use POSIX-style shm_open/mmap put a ".shm" somewhere in your
mask. eg. "/apc.shm.XXXXXX" You can also set it to "/dev/zero" to use your
kernel's /dev/zero interface to anonymous mmap'ed memory. Leaving it
undefined will force an anonymous mmap.
(Default: "")
apc.slam_defense On very busy servers whenever you start the server or
modify files you can create a race of many processes all trying to cache the
same file at the same time. This option sets the percentage of processes that
will skip trying to cache an uncached file. Or think of it as the probability of
a single process to skip caching. For example, setting this to 75 would mean
that there is a 75% chance that the process will not cache an uncached file. So
the higher the setting the greater the defense against cache slams. Setting this
to 0 disables this feature.
(Default: 0)
apc.file_update_protection When you modify a file on a live web server
you really should do so in an atomic manner. That is, write to a temporary file
and rename (mv) the file into its permanent position when it is ready. Many text
editors, cp, tar and other such programs don't do this. This means that there is
a chance that a file is accessed (and cached) while it is still being written
to. This file_update_protection setting puts a delay on caching brand new files.
The default is 2 seconds which means that if the modification timestamp (mtime)
on a file shows that it is less than 2 seconds old when it is accessed, it will
not be cached. The unfortunate person who accessed this half-written file
will still see weirdness, but at least it won't persist. If you are certain you
always atomically update your files by using something like rsync which does
this correctly, you can turn this protection off by setting it to 0. If you have
a system that is flooded with io causing some update procedure to take longer
than 2 seconds, you may want to increase this a bit.
(Default: 2)
apc.enable_cli Mostly for testing and debugging. Setting this enables APC
for the CLI version of PHP. Normally you wouldn't want to create, populate and
tear down the APC cache on every CLI request, but for various test scenarios it
is handy to be able to enable APC for the CLI version of APC easily.
(Default: 0)
apc.max_file_size Prevents large files from being cached.
(Default: 1M)
apc.stat Whether to stat the main script file and the fullpath includes.
If you turn this off you will need to restart your server in order to update
scripts.
(Default: 1)
Hi Navid, Could you post
Hi Navid,
Could you post this issue in the support forum.
Thanks,
Chris
PS: Do you get that white page for every php page you try to load ?
Also I posted a reply to your eAccelerator issue. Might be a similar problem:
Most of my articles can't simply be copied and pasted into the php.ini file. Since I usually don't add the comment delimiter ";" in my articles.
Cheers,
Chris
Access Violations
I installed the new APC for PHP 5.1.6
I got almost instantly tons of errors:
PHP has encountered an Access Violation at 01F6215F
I MUST have been missing something
I run IIS.
Which versions?
Which versions (OS, IIS, PHP, APC)?
I noticed many forget to details their software versions. Please try to always post versions. With version information your post goes from "not very helpful" to very helpful.
Also it is usually very helpful to know if you every had this working or if this is some new install issue.
Thanks,
C
Same here - access violations
I posted a host of details in the EA thread with no reply.
This article is about APC
It appears that since 0.9.4, EA crashes on a regular basis for certain (all under
load ?) configurations.
I'm trying to document peoples experiences with EA to determine if a pattern
emerges.
See:
eAccelerator crash : CALL FOR YOUR FEEDBACK
At this point, it looks like most posts under that article are using W2K3
(Windows 2003 Server). I've already heard of some open-source application having
problem under W2K3. Might be due to DEP or similar ?
I'm probably going to set-up Apache, EA on a W2K server to see if it's more
stable.
UPDATE: disabling DEP from the boot.ini did not do much.
However running 4.3.11 seems to make a world of difference. I got about 6 Apache server running with different compination of Apache, PHP and Accelerators will post my results once my latest Apache 2.2.3 + PHP 4.3.11 + EA runs stable for at least 1 day. The site now on PHP 4.3.11 usually got a few "windows dumps" per day so it should be pretty conclusive.
Will be tracking my finds here:
Running Apache + PHP + Accelerators under Windows 2003
For now, you might want to try to restart (to solve any memory leak) the web service when traffic is low on your site. For example, you can create a scheduled task every night.
All are volunteers here. If no one gets back to you, it could means 1 of 3 things:
a) No time at the moment
b) No solution
c) Response is already on this site
Please be patient.
Cheers,
C
I have the following
I have the following problem.
When updating files (editing a .php file for example), APC will NOT update it's cached file. That means that it will continue to serve the old file, rather than the new that I edited.
Is there a workaround to this?
I did not have this problem with eAccelerator. It was automatically updating files that i edited.
Thanx!
Alex
Hi Alex, Just tested on
Hi Alex,
Just tested on Windows 2003 Server. This works fine here with PHP 4.4.4 & APC 3.0.11.
Make sure it's not some caching issue (browser?, web server ?).
Here are my apc settings right now:
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 96
apc.optimization = 0
apc.num_files_hint = 1024
apc.ttl = 7200
apc.user_ttl = 7200
apc.gc_ttl = 3600
apc.cache_by_default = On
apc.filters =
apc.mmap_file_mask =
apc.slam_defense = 0
apc.file_update_protection = 2
apc.enable_cli = 0
;apc.stat = 0
apc.max_file_size = 2M
Is there a binary for the new APC 3.0.11 (stable)?
I noticed that Apache, PHP, and APC just recently came out with new versions. I can find the windows binaries for Apache and PHP but I wasn't able to find any binaries (the dll file) for APC 3.0.11. The file should be a simple dll under the name: php_apc.dll
Any idea?
Thanks,
APC binaries for PHP 5 + PHP 4
I also noticed that php_apc.dll releases (ie the windows binaries) were a few versions behind. So, I compiled my first APC versions from the source.
APC on IIS and PHP 5.1.2.2
I tried installing APC on IIS and this is the result.
"The remote procedure call failed."
That shows whenever I load a PHP file. I checked to make sure TMP was set and made sure IUSR had rights to it.
What could this mean?
Thanks, Jamal
Please post support type
Please post support type issues into the forum section of Sitebuddy.
Moved you question here:
APC on IIS and PHP 5.1.2.2
Also include the version of software (IIS? Windows 2003 Server ?)
Thanks,
C
APC on Windows
Hi,
Is there anyway of setting apc.mmap_file_mask for Windows?
I've tried the following settings but they aren't working
apc.mmap_file_mask = "D:/www/temp/apc.XXXXXX"
apc.mmap_file_mask = "D:\www\temp\apc.XXXXXX"
I've also tried creating a directory C:\tmp but no files were created.
BTW, where does APC save files on windows?
Thanks
Hi, If I recall correctly it
Hi,
If I recall correctly it uses the TMP or TEMP system variable for the location of the temp files.
Make sure you have the proper permissions on the folder containing your temp files. The anonymous account (usually IUSR_???) and the service account (if you defined one) should have read/write permissions on the this folder.
Cheers,
C


delicious
digg
reddit
google
technorati
White page
APC after using default config from useful files and this article i still get the white pages, even after removing the setting you mentioned and setting it to 1 or 0.
Any idea what it should be correctly?