的auto_prepend_file不是在命令行模式下工作(auto_prepend_file is

2019-09-30 03:03发布

我不能得到的auto_prepend_file我的Mac上运行:

# 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。

你有什么我可以作出错误的任何想法?

Answer 1:

auto_prepend_file当您直接通过运行代码不执行-r命令行开关。 当你在命令行执行PHP文件,如果不考虑PHP本身从CLI调用或它在可执行文件的家当指定它工作正常。



Answer 2:

这是记录的行为:

此选项仅用于非常基本的代码,因此一些配置指令(如的auto_prepend_file和auto_append_file所)在此模式下被忽略。

http://www.php.net/manual/en/features.commandline.options.php



Answer 3:

一个解决办法是管你要执行的文件内容php ,而不是使用-r 。 例如:

echo "<?php dump('anuise');" | php


文章来源: auto_prepend_file is not working in cli mode