出于测试目的,我在本地主机上运行了 gearman。所以我从 php 命令行运行 gearman worker.php 文件。当我在正常的 apache 模式下测试它时,mongoDB 工作得很好,但是当它从 gearman 工作文件运行时,我收到错误“致命错误:找不到类 'Mongo'”。现在 Mongo 类来自 pecl 和 php.ini 中的 mongo.so 扩展。所以是的,试图弄清楚为什么从 CLI 运行的 php 文件是不同的。它是否使用单独的 php.ini 文件?
3 回答
您可以通过执行来检查 CLI 版本正在加载哪些 .ini 文件php --ini
。如果您的 PHP 是由发行版提供的,那么它很可能有两个单独的 .ini 集,一个用于基于 Web 的,一个用于 CLI。phpinfo()
您也可以从它在线运行时获取等效信息。
要强制它加载特定的 .ini,您可以使用php -c /path/to/file.ini
.
Well a simple find / -name php.ini answered that question for me. So yes, there is a separate php.ini file. Where I needed to add the line extension=mongo.so.
It sounds like either you're loading different ini files or you've got multiple instances of php installed on your machine and apache is using a different one. Make the script v.php:
<?php phpinfo();
then try running it from CLI and then viewing it via localhost. EG:
php v.php
and