PHP - An external Class/library is accessible from apache but not from phpunit

匆匆过客 提交于 2019-12-11 03:53:35

问题


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.

Dont phpunit use the same php.ini which apache uses?

In phpunit I get following error.

PHP Fatal error: Class 'ZMQContext' not found in /home/idlecool/checker/testcases/checkerTest.php on line 53


回答1:


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 for Apache
  • and /etc/php5/cli/php.ini for command-line -- and PHPUnit runs as a command-line application.


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.

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.


For example, you could have a /etc/php5/conf.d/zmq.ini file, containing something like :

extension=zmq.so

(of course, you'll have to put the name of the right .so file)



来源:https://stackoverflow.com/questions/9241210/php-an-external-class-library-is-accessible-from-apache-but-not-from-phpunit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!