操作码 (APC/XCache)、Zend、Doctrine 和自动加载器 [英] Opcode (APC/XCache), Zend, Doctrine, and Autoloaders

查看:26
本文介绍了操作码 (APC/XCache)、Zend、Doctrine 和自动加载器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 APC 或 XCache 作为操作码来缓存我的 php 页面.我正在将它与 Zend 和 Doctrine 一起使用,但它的自动加载器出现问题.

I am trying to use either APC or XCache as an opcode to cache my php pages. I am using it with Zend and Doctrine and it's having a problem with the autoloader.

如果我尝试使用 APC,我会得到以下信息:

If I try with APC, I get the following:

Fatal error: spl_autoload() [<a href='function.spl-autoload'>function.spl-autoload</a>]: 
  Class Doctrine_Event could not be loaded in 
  C:\[mydir]\library\doctrine\Doctrine\Record.php on line 777

如果我尝试使用 XCache,我会得到以下结果:

If I try with XCache I get the following:

PHP Fatal error: Cannot redeclare class Zend_Registry in 
  C:\[mydir]\library\zendframework\Zend\Registry.php on line 0

我在 Windows 机器上运行 Zend 1.9.1、Doctrine 1.1.

I'm running Zend 1.9.1, Doctrine 1.1 on a windows box.

我的引导程序如下:

set_include_path(dirname(__FILE__).'/../library/zendframework'
. PATH_SEPARATOR . dirname(__FILE__).'/../library/doctrine'.....

require 'Zend/Loader/Autoloader.php';

$loader = Zend_Loader_Autoloader::getInstance();
$loader->suppressNotFoundWarnings(false);
$loader->setFallbackAutoloader(true);

据我所知,使用 APC 或 xcache 几乎是提高性能的必要条件,但我似乎无法使其正常工作.有什么想法吗?

From what I've read, using APC or xcache is almost a must for performance, but I can't seem to get it working. Any ideas?

推荐答案

您可以在 index.php 的末尾添加Zend_Session::writeClose(true);".
这将在必要的对象(Zend_Loader 等)被破坏之前将会话写入持久状态.

You could put a "Zend_Session::writeClose(true);" at the end of your index.php.
This will write the session into a persistent state before necessary Objects (Zend_Loader etc.) get destructed.

更好:将其注册为 shutdown功能.
所以即使你使用exit(), die()fatal error 也会被执行:

Better: Register it as shutdown function.
So it will be executed even if you use exit(), die() or a fatal error occures:

register_shutdown_function(array('Zend_Session', 'writeClose'), true);

这篇关于操作码 (APC/XCache)、Zend、Doctrine 和自动加载器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆