操作码 (APC/XCache)、Zend、Doctrine 和自动加载器

发布于 2024-08-04 00:49:31 字数 996 浏览 14 评论 0原文

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

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

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,我会得到以下信息:

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。

我的引导程序如下:

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 几乎是性能的必须,但我似乎无法让它工作。有什么想法吗?

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.

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

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

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

My bootstrap is as follows:

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);

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

橘寄 2024-08-11 00:49:31

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

更好:将其注册为关闭功能.
因此,即使您使用 exit()die() 或发生 致命错误,它也会被执行:

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

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.

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);
梦里梦着梦中梦 2024-08-11 00:49:31

它可能类似于自定义会话处理和 APC 缓存的问题。如果您已分配自定义会话处理程序,它将在 PHP 中使用 RSHUTDOWN 进行注册。这与 APC 使用的例程相同,因此会在 PHP 中产生内部冲突,并且您的自定义会话处理程序在所有情况下都不会关闭。

因此,您必须确保在关闭时手动关闭自定义会话处理程序在

index.php 末尾放置 "Zend_Session::writeClose(true);" 并不是最好的方法如果您有任何出口;在任何地方调用您的脚本。

最好以这种方式注册关闭处理程序:

function shutdown()
{
 Zend_Session::writeClose(true);
}

register_shutdown_function('shutdown');

将其放在 index.php 文件的顶部,以确保在运行任何其他脚本之前注册关闭过程。

It is probably similar to the problem with custom session handling and APC-cache. If you have assigned a custom session handler it is registered with RSHUTDOWN in PHP. It is the same routine that APC uses and will therefor create an internal conflict in PHP and your custom session handler will not close in all situations.

So you will have to make sure you manually close the custom session handler at shutdown

Putting a "Zend_Session::writeClose(true);" at the end of your index.php is not the best way to do that in case you have any exit; calls in your scripts anywhere.

It is better to register a shutdown handler in this way:

function shutdown()
{
 Zend_Session::writeClose(true);
}

register_shutdown_function('shutdown');

Put that in top of your index.php file to make sure that the shutdown procedure is registered before any other scripts are run.

起风了 2024-08-11 00:49:31

还有其他东西破坏了包含路径吗?也许尝试在第一个 APC 示例中的该行之前注销包含路径。

XCache 确实很奇怪。但那个项目已经死了,我不相信它在 PHP 5.2+ 上。试试 eaccelerator 吗?我们对此非常幸运。

Is there something else mucking the include path? Maybe try to log out the include path right before that line in your first APC example.

The XCache one is really weird. That project is pretty dead though, and I'd not trust it on PHP 5.2+. Try eaccelerator instead? We've had the best luck with it.

明明#如月 2024-08-11 00:49:31

本杰明·克里默,你是一个救星。虽然上述(原始)问题是会话自动加载的特殊情况,但关闭会话似乎是此类情况的通用解决方案。但请注意:

Zend_Session::writeClose(true); 放在脚本末尾可能并不总是能消除它,因为您可能有 exit; 的,die();'s 等在您的代码中。在这种情况下,您可以使用

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

或简单地

使用 register_shutdown_function('session_write_close');

如果您这样做不使用 Zend 进行会话。

Benjamin Cremer, you're a life saver. While the above (original) problem is a special case of autoloading with sessions, closing the session seems to be a general solution for such cases. A note though:

Placing Zend_Session::writeClose(true); at the end of your scripts may not always cut it, since you may have exit;'s, die();'s, etc in your code. In this case, you can use

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

or, simply

register_shutdown_function('session_write_close');

if you do not use Zend for sessions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文