这很有趣。
无论如何,PHP命令提供了 :
-r <code> Run PHP <code> without using script tags <?..?>
-R <code> Run PHP <code> for every input line
您可以这样使用PHP的 :
PHP -r 'echo function_exists("foo") ? "yes" : "no";'
上面的PHP命令应该 no
并 0
如您所见:
>>> PHP -r 'echo function_exists("foo") ? "yes" : "no";'
no
>>> echo $? # print the return value of the prevIoUs command
0
另一个有趣的开关是 :
-a Run as interactive shell
这 ,但是如果您不想安装facebook制作的php真棒交互式shell来获取制表符的完成情况,历史记录等等,则可以 :
>>> PHP -a
Interactive shell
PHP > echo function_exists("foo") ? "yes" : "no";
no
PHP >
像我的@R_480_2419@ * es (在Ubuntu和Arch上 测试 )那样在您的盒子上运行,则可能是您的PHP设置模糊或损坏* 。如果运行此命令:
PHP -i | grep 'API'
您 看到:
Server API => Command Line Interface
,这意味着 。尝试PHP-cli,也许它是您操作系统中可用的软件包或命令。
看到您的PHP命令使用CLI(命令行界面)SAPI(服务器API),请运行PHP -h | grep code
以 允许您在版本/设置中运行代码。
另外两个例子,只是为了确保它可以在我的盒子上工作:
>>> PHP -r 'echo function_exists("sg_load") ? "yes" : "no";'
no
>>> PHP -r 'echo function_exists("print_r") ? "yes" : "no";'
yes
另外,请注意,有可能在CLI中而不是CGI或Apache SAPI中加载了扩展。 ,例如/etc/PHP/cli/PHP.ini
vs /etc/PHP/cgi/PHP.ini
与vs/etc/PHP/apache/PHP.ini
在Gentoo盒子上。找出与哪个ini文件一起使用PHP -i | grep ini
。