【问题标题】:xampp apache apc not working in symfony2xampp apache apc 在 symfony2 中不工作
【发布时间】:2015-07-30 21:20:55
【问题描述】:

我有高 TTFB(到第一个字节的时间)的问题。我必须安装 APC 或 xcache,这两者都没有在我的 apache 网络服务器上启动。

请告知如何安装 APC 或 xcache。 opcache已安装,但在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

在我的 app/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);

【问题讨论】:

  • 如果 PHP > 5.5,您应该使用APCu - 从 Zend OpCache 附带的 5.5 PHP 开始。不妨读一读:stackoverflow.com/questions/9611676/…
  • 我也不清楚您要做什么。您是否尝试设置缓存以最大程度地减少数据库交互?也许定义慢?通常更多的是标志应用程序设计或不稳定的硬件/网络。
  • 我想做操作码和数据库缓存,但现在我的重点是让操作码缓存工作。我刚开始学习 Symfony2 并被这些基本问题所困扰。我在网络服务器方面也没有很多经验。数据库耗时不到 10ms,twig 耗时 1400ms。我想操作码缓存会有所帮助,但我会浏览您在上面粘贴的链接。感谢您的输入。
  • ficuser,你可能是对的。我主页的 TTFB 已从超过 4 秒降至 1.5 秒以下。我可能不得不使用 APCu,因为所有进行数据库交互的页面都非常慢(大约 4 秒)。我们在 APCu 的 config_prod.yml 中放了什么?例如(请参阅我的问题中的相关文本)缓存:validator.mapping.cache.apcu?

标签: php apache symfony apc xcache


【解决方案1】:

使用 opcache 和 APCu 解决了这个问题。 TTFB 现在已从 6-10 秒降至 100 毫秒。感谢您的帮助。我还有一个关于管理缓存的问题,我会在完成研究后发布一个单独的问题。

我当前的 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);

【讨论】:

    猜你喜欢
    • 2015-11-23
    • 2016-04-04
    • 2013-12-11
    • 2013-12-12
    • 2017-07-21
    • 1970-01-01
    • 2010-09-30
    • 2017-04-16
    • 1970-01-01
    相关资源
    最近更新 更多