views:

76

answers:

3

For test purposes I have gearman running on localhost. So I run the gearman worker.php file from php command line. When I test this in normal apache mode, mongoDB works just fine, but when it runs from the gearman worker file I get the error "fatal error: class 'Mongo' not found". Now the Mongo class comes from pecl and the mongo.so extension in php.ini. SO yeah, trying to figure out why a php file run from CLI is different. Does it use a separate php.ini file?

+2  A: 

You can check which .ini files are being loaded by the CLI version by doing php --ini. If your PHP was provided by a distro, it's very possible for it to have two seperate .ini sets, one for web-based and one for CLI. You can get the equivalent info from phpinfo() when it's running online as well.

To force it to load a particular .ini, you can use php -c /path/to/file.ini.

Marc B
A: 

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.

Brett
A: 

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

http://localhost/v.php

jacobangel