我的mac上无法运行auto_prepend_file:
# cat /opt/local/lib/php/test.php
<?php
function test() { return 'foo'; }
# php --ini | grep php.ini
Configuration File (php.ini) Path: /opt/local/etc/php5
Loaded Configuration File: /opt/local/etc/php5/php.ini
# cat /opt/local/etc/php5/php.ini | grep auto_prepend_file
auto_prepend_file = "/opt/local/lib/php/test.php"
# ls -la /opt/local/etc/php5/php.ini
-rw-r--r-- 1 root admin 68630 Jul 27 13:53 /opt/local/etc/php5/php.ini
# php -r "echo ini_get('auto_prepend_file');"
/opt/local/lib/php/test.php
然后……
# php -r "echo test();"
Fatal error: Call to undefined function test() in Command line code on line 1
# php -i | grep auto_prepend_file
auto_prepend_file => /opt/local/lib/php/test.php => /opt/local/lib/php/test.php
它通过(重启的)apache工作。
你知道我可能做错了什么吗?当直接通过-r
命令行开关运行代码时,不执行auto_prepend_file
。当您在命令行上执行PHP文件时,无论PHP本身是从CLI调用还是在可执行文件的shebang中指定,它都可以正常工作。
记录的行为:
http://www.php.net/manual/en/features.commandline.options.php这个选项只适用于非常基本的代码配置指令(如auto_prepend_file和Auto_append_file)在此模式下被忽略。
一个解决方法是将您想要执行的文件内容管道到php
而不是使用-r
。例如:
echo "<?php dump('anuise');" | php