可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
How can I run a php script from the command line using the php interpretor which is used to parse web scripts.
More detail -
I have a phpinfo.php
file which if accessed from the web shows that gearman
is installed. However if I run the phpinfo.php
from the command line using - php phpinfo.php
and grep
for gearman
, I don't find it. So both phps are different. I need to run a script which the php
on which gearman
is installed.
How can I do this?
回答1:
UPDATE:
After misunderstanding, I finally got what you are trying to do. You should check your server configuration files; are you using apache2 or some other server software?
Look for lines that start with LoadModule php
... There probably are configuration files/directories named mods
or something like that, start from there.
You could also check output from php -r 'phpinfo();' | grep php
and compare lines to phpinfo();
from web server.
To run php
interactively:
(so you can paste/write code in the console)
php -a
To make it parse file and output to console:
php -f file.php
Parse file and output to another file:
php -f file.php > reults.html
Do you need something else?
To run only small part, one line or like, you can use:
php -r '$x = "Hello World"; echo "$x\n";'
If you are running linux then do man php
at console.
回答2:
(I know this is an old question)
On SuSE, there are two different configuration files for PHP: one for Apache, and one for CLI (command line interface). In the /etc/php5/ directory, you will find an "apache2" directory and a "cli" directory. Each has a "php.ini" file. The files are for the same purpose (php configuration), but apply to the two different ways of running PHP. These files, among other things, load the modules PHP uses.
If your OS is similar, then these two files are probably not the same. Your Apache php.ini is probably loading the gearman module, while the cli php.ini isn't. When the module was installed (auto or manual), it probably only updated the Apache php.ini file.
You could simply copy the Apache php.ini file over into the cli directory to make the CLI environment exactly like the Apache environment.
Or, you could find the line that loads the gearman module in the Apache file and copy/paste just it to the CLI file.