0

I have prollem of high TTFB (time to first byte). I have to install APC or xcache, both of which are not getting started on my apache webserver.

Please advise how to install the APC or xcache. opcache is installed, but I do not know how to use in Symfony2.

rpandey@FIRST-PC /c/xampp/htdocs/ims
$ php -v
C:\xampp\php\ext\php_apc.dll doesn't appear to be a valid Zend extension
PHP 5.6.11 (cli) (built: Jul  9 2015 20:55:40)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies


In the php.ini I have,
[APC]
zend_extension = "C:\xampp\php\ext\php_apc.dll"
;specifies the size for each shared memory segment 8MB to start
apc.shm_size=8M
;max amount of memory a script can occupy
apc.max_file_size=1M
apc.ttl=0
apc.gc_ttl=3600
; means we are always atomically editing the files
apc.file_update_protection=0
apc.enabled=1
apc.enable_cli=1
apc.cache_by_default=1
apc.include_once_override=0
apc.localcache=0
apc.localcache.size=512
apc.num_files_hint=1000
apc.report_autofilter=0
apc.rfc1867=1
apc.slam_defense=0
apc.stat=1
apc.stat_ctime=0
apc.ttl=7200
apc.user_entries_hint=4096
apc.user_ttl=7200
apc.write_lock=1

In my app/config/config_prod.yml

I want to do both framework:

framework:
    validation:
        cache: validator.mapping.cache.apc
    serializer:
        cache: serializer.mapping.cache.apc

#doctrine:
#    orm:
#        metadata_cache_driver: apc
#        result_cache_driver: apc
#        query_cache_driver: apc

I have commented doctrine for now. Will deal with it later.

In, app.php: I want to do the following

$apcLoader = new ApcClassLoader(sha1(__FILE__), $loader);
$loader->unregister();
$apcLoader->register(true);
  • Feel like you should be using [APCu](https://pecl.php.net/package/APCu) if PHP > 5.5 - as of 5.5 PHP shipped with Zend OpCache. Maybe give this a read: http://stackoverflow.com/questions/9611676/is-apc-compatible-with-php-5-4-or-php-5-5 – ficuscr Jul 30 '15 at 21:25
  • I'm not clear what you are trying to do either. Are you trying to setup a cache to minimize database interactions? Maybe define slow? Typically more a sign application design or wonky hardware / network. – ficuscr Jul 30 '15 at 21:47
  • I want to do both the opcode and database caching, but for now my focus is to get the opcode caching working. I just started learning Symfony2 and am stuck with these basic issues. I do not have lot of experience in web servers too. The database takes less than 10ms, the twig takes 1400ms. I guess opcode caching will help but I will go through the link that you pasted above.Thanks for your input. – Rajeev Pandey Jul 31 '15 at 01:28
  • ficuser, you may be right. The TTFB for my home page has come down to under 1.5 secs from over 4 secs. I might have to use APCu because all pages that do database interaction are very slow (about 4 secs). What do we put in the config_prod.yml for APCu? For instance (please refer the relevent text in my question )cache: validator.mapping.cache.apcu? – Rajeev Pandey Jul 31 '15 at 02:22

1 Answers1

0

The problem got resolved by using both the opcache and APCu. The TTFB has now come down from 6-10 secs to 100 ms. Thanks ficuscr for your help. I have another question about managing cache for which I will post a seperate question after I have done my research.

My current app.php looks like this

<?php

use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
//$loader = require_once __DIR__.'/../app/AppCache.php';

// Enable APC for autoloading to improve performance.
// You should change the ApcClassLoader first argument to a unique prefix
// in order to prevent cache key conflicts with other applications
// also using APC.

$loader = new ApcClassLoader('ims', $loader);
//$loader->unregister();
//$apcLoader->register(true);
$loader->register(true);

require_once __DIR__.'/../app/AppKernel.php';
require_once __DIR__.'/../app/AppCache.php';

$kernel = new AppKernel('prod', true);
$kernel->loadClassCache(); 
$kernel = new AppCache($kernel); //comment it

// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
//$response->setETag(md5($response->getContent()));
                $response->setPublic(); // make sure the response is public/cacheable
                //$response->isNotModified($request);
                $response->setMaxAge(400);
                $response->setSharedMaxAge(500);
$response->send();
$kernel->terminate($request, $response);