4

My problem:

I am making Apache Benchmark test to see if CakePHP APC engine works. However, if I setup Cake's caching configuration to use APC engine, the cache files with serialized cached data are still being created in tmp folder, which make me think that file caching is being used.

I also get no performance benefit: using APC and File engines, test results are ~ 4 sec. If I hardcode plain apc_add() and apc_fetch functions in my controller, the test result gets better: ~3.5 sec.

SO the APC is working, but Cake somewhy can't use it.

My setup:

bootstrap.php:

/*Cache::config('default', array(
    'engine' => 'File', 
    'duration'=> '+999 days',
    'prefix' => 'file_',
));*/
Cache::config('default', array(
    'engine' => 'Apc',
    'duration'=> '+999 days',
    'prefix' => 'apc_',
));

controller:

$catalogsLatest = Cache::read('catalogsLatest');
if(!$catalogsLatest){
$catalogsLatest = $this->Catalog->getCatalogs('latest', 5, array('Upload'));
Cache::write('catalogsLatest', $catalogsLatest);
}

php.ini:

[APC]
apc.enabled = 1
apc.enable_cli = 1 
apc.max_file_size = 64M

If I check Cache::settings() in controller before or after cache executuon, I get these results:

Array
(
    [engine] => Apc
    [path] => E:\wamp\www\cat\app\tmp\cache\
    [prefix] => apc_
    [lock] => 1
    [serialize] => 
    [isWindows] => 1
    [mask] => 436
    [duration] => 86313600
    [probability] => 100
    [groups] => Array
        (
        )
)

I am using CakePHP 2.2.4.

user2183237
  • 41
  • 1
  • 3
  • First of all, I think this configuration should be put inside app/Config/core.php, not in your bootstrap.php. Apparently the configuration is recognised, so this should not be the problem. The cache files written in the app/tmp directory may be cache files written by CakePHP itself, have you checked their content? To check if anything is written to APC, you can use the APC control panel, which can be accessed via the apc.php file that is included with APC. Not a direct answer, but maybe this helps – thaJeztah Mar 18 '13 at 19:24
  • 1
    @thaJeztah Only the core caches go in core.php. The default cache config and other user defined ones go in bootstrap.php. – ADmad Mar 18 '13 at 20:29
  • @ADmad thanks for the info. Did this change in CakePHP 2.x? This used to be in core.php in CakePHP 1.x, or am I mistaken? – thaJeztah Mar 18 '13 at 20:37
  • @thaJeztah Yes it changed in 2.x. – ADmad Mar 20 '13 at 14:16
  • @ADmad I'll check the config of my projects. Thx :) – thaJeztah Mar 20 '13 at 19:10
  • Are you by any chance using fast-cgi php in the background ? If yes then APC will not work - as fast-cgi spawns process per user and kills it after, therefore nothing persists in cache longer than request itself. http://stackoverflow.com/a/1516995/2000799 – johhniedoe Jul 23 '13 at 08:25

1 Answers1

0

Yes, of course APC cache will boost up your cakephp powered application performance So let's check your settings from my following instructions and let me know after following the instruction do a benchmark test and tell me the result. You can cache whole your HTML view file in cache with APC cache engine in CakePHP. Cake's CacheHelper will do that job for you. Suppose you have a PostsController and you want to cache all your view files related this controller. In this case first of all you have to define the following code in your controller.

   class PostsController extends AppController {
       public $helpers = array('Cache');
   }

And in your bootstrap.php file you have to add the CacheDispatcher.

   Configure::write('Dispatcher.filters', array(
        'CacheDispatcher'
       )
   );

And now again in your PostsController you have to tell about the cache files.

    public $cacheAction = array(
        'view' => 36000,
        'index'  => 48000
    );

This will cache the view action 10 hours, and the index action 13 hours.

Let me know your apache benchmark tool test result. I think the mostly similar question are being discussed on another thread https://stackoverflow.com/a/18916692/1431786 check it out.

Thanks.

Community
  • 1
  • 1
Shaharia Azam
  • 1,948
  • 19
  • 25