PHP - 可以从 apache 访问外部类/库,但不能从 phpunit 访问 [英] PHP - An external Class/library is accessible from apache but not from phpunit
问题描述
我在我的 Web 应用程序中使用 ZeroMQ 套接字库.我已经配置了 php.ini 以便 Apache 可以使用 ZMQ 但我不知道 phpunit 可以如何使用它.
I am using ZeroMQ socket library in my web application. I have configured php.ini so Apache can use ZMQ but I dont know how phpunit can use it.
phpunit 和 apache 使用的 php.ini 不一样吗?
Dont phpunit use the same php.ini which apache uses?
在 phpunit 中出现以下错误.
In phpunit I get following error.
PHP 致命错误:在第 53 行的/home/idlecool/checker/testcases/checkerTest.php 中找不到ZMQContext"类
推荐答案
哪个 php.ini
文件用于 Apache 和命令行通常取决于您的 Linux 发行版;如果使用 Debian 或 Ubuntu,您通常会:
Which php.ini
file is used for Apache and command-line generally depends on your Linux distribution ; if using Debian or Ubuntu, you'll generally have :
/etc/php5/apache2/php.ini
用于 Apache- 和
/etc/php5/cli/php.ini
用于命令行——PHPUnit 作为命令行应用程序运行.
/etc/php5/apache2/php.ini
for Apache- and
/etc/php5/cli/php.ini
for command-line -- and PHPUnit runs as a command-line application.
但请注意,(默认情况下在 Ubuntu 上确实如此),/etc/php5/conf.d/
中的所有 .ini
文件> 目录将在 Apache 和 CLI 模式下加载.
But note that quite often (it's true on Ubuntu, by default), all .ini
files from the /etc/php5/conf.d/
directory will be loaded in both Apache and CLI modes.
这意味着,如果您希望在两种模式下都加载一个扩展,您应该在该目录中创建一个 .ini
文件,加载并配置它.
Which means that, if you want an extension to be loaded in both modes, you should create a .ini
file in that directory, loading and configuring it.
例如,您可以有一个 /etc/php5/conf.d/zmq.ini
文件,其中包含如下内容:
For example, you could have a /etc/php5/conf.d/zmq.ini
file, containing something like :
extension=zmq.so
(当然,您必须输入正确的.so
文件的名称)
(of course, you'll have to put the name of the right .so
file)
这篇关于PHP - 可以从 apache 访问外部类/库,但不能从 phpunit 访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!