[nycphp-talk] Using APC to improve performance.
Che Hodgins
chehodgins at gmail.com
Tue Mar 31 00:30:56 EDT 2009
Hi Konstantin,
On Mon, Mar 30, 2009 at 8:03 PM, Konstantin Rozinov <krozinov at gmail.com> wrote:
>
> Hi folks,
>
> I recently installed APC (http://pecl.php.net/package/APC) to see how
> it works. Currently, I'm just using the opcode (file) caching and
> already the response time is about 4x faster. No code changes were
> required and it was as easy as just enabling APC in php.ini. Now I'm
> interested in trying out the "user variable caching" to see if I can
> get any more improvement in response time. I know that this will
> require code changes and the use of the APC functions (like apc_add(),
> apc_fetch(), etc.)
>
> For example, I have a configuration file, which has about 400+ defined
> constants for the web application I'm working on. I've read in the
> APC documentation and elsewhere that define() is notoriously slow (not
> sure why??).
>
> 1. Will storing these constants in APC help?
Although I don't use apc_define_constants(), I'm sure some gains can
be achieved. The question is whether Cost > Reward. I recommend
profiling your code with an extension such as Xdebug to see how much
you can save by using apc_define_constants.
>
> 2. How would you store these constants? Just use apc_add()? Or use
> apc_ load_ constants() (the APC docs say that this doesn't work as
> well as expected?!)?
You should use apc_define_constants() and apc_load_constants(). Since
you won't know if they are already loaded you will need something
like:
<?php
$loaded = apc_load_constants('my_app');
if ($loaded == false) {
$configuration = parse_ini_file('configuration.ini');
apc_define_constants('my_app', $configuration);
}
After which you will can access the constants as you normally would.
>
> 3. If I'm already using the opcode (file) caching, will it make any
> difference store the 400+ defined constans in APC?
It should, if not I don't see why they would have created these two functions.
>
> 4. Any links to really good APC howtos or tutorials would be greatly
> appreciated!
Before starting to optimize where you think there may be problems, I
recommend you actually find out where the problems are. Using tools
like xdebug and kcachegrind you can pretty quickly find bottlenecks
and you won't waste as much time guessing.
Good luck!
Che
>
> Thanks for any help and tips.
> Konstantin
> _______________________________________________
> New York PHP User Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/show_participation.php
More information about the talk
mailing list