2015-07-30 3 views
0

У меня есть расширенный высокий TTFB (время до первого байта). Я должен установить APC или xcache, оба из которых не запускаются на моем веб-сервере apache.xampp apache apc не работает в symfony2

Просьба сообщить, как установить APC или xcache. opcache установлен, но я не знаю, как его использовать в Symfony2.

[email protected] /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 

В моем приложение/Config/config_prod.yml

Я хочу сделать как основу:

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 

я прокомментировал учение сейчас. Поговорим об этом позже.

В, app.php: Я хочу сделать следующее

$apcLoader = new ApcClassLoader(sha1(__FILE__), $loader); 
$loader->unregister(); 
$apcLoader->register(true); 
+0

Почувствуйте, как вы должны использовать [APCu] (https://pecl.php.net/package/APCu), если PHP> 5,5 - от 5,5 PHP поставляется с Zend OpCache. Возможно, прочитайте это: http://stackoverflow.com/questions/9611676/is-apc-compatible-with-php-5-4-or-php-5-5 – ficuscr

+0

Я не понимаю, что вы пытаетесь сделайте это. Вы пытаетесь настроить кеш, чтобы минимизировать взаимодействие с базами данных? Может быть, определить медленный? Как правило, это больше, чем дизайн знаковых приложений или воинственное оборудование/сеть. – ficuscr

+0

Я хочу сделать как кеширование кода операции, так и базу данных, но сейчас я сосредоточен на том, чтобы работать с кешированием операций. Я только начал изучать Symfony2 и застрял в этих основных проблемах. У меня нет большого опыта работы на веб-серверах. База данных занимает менее 10 мс, веточка занимает 1400 мс. Я думаю, что кэширование кода операции поможет, но я перейду по ссылке, которую вы вставили выше. Спасибо за ваш вклад. –

ответ

0

Проблема получила решена как с помощью opcache и APCu. TTFB теперь опустился с 6-10 секунд до 100 мс. Спасибо ficuscr за вашу помощь. У меня есть еще один вопрос об управлении кешем, для которого я опубликую отдельный вопрос после того, как сделаю свое исследование.

Мой текущий app.php выглядит следующим образом

<?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); 
Смежные вопросы