开发者

Custom php.ini when using #!/usr/bin/php

开发者 https://www.devze.com 2023-02-18 10:06 出处:网络
I have a script in which I am trying to load a custom php.ini file.The script is run on *nix systems via a #!/usr/bin/php -qc /path/to/php.ini header.When doing this, however, PHP reports that the loa

I have a script in which I am trying to load a custom php.ini file. The script is run on *nix systems via a #!/usr/bin/php -qc /path/to/php.ini header. When doing this, however, PHP reports that the loaded php.ini file does not exist, i.e. none is loaded.

If I execute php -qc /path/to/php.ini /path/to/script in the command line directly, it picks up the p开发者_运维问答hp.ini -- is it possible to override the php.ini file using the #! notation?


PHP does not like parsing arguments from the shebang. It only allows one to be present. You can however trick it by omitting the space for the first argument parameter:

#!/usr/bin/php -qc/etc/php5/my.ini

(Obviously this method only works for one such parameter with concatenated argument.)


You can workaround this shebang portability specification fail by wrapping your PHP script in a Shell script:

#!/bin/sh
SCRIPT_PATH="$(dirname $0)"
/usr/bin/env php -qc /path/to/php.ini -f $SCRIPT_PATH/my_original_script.php
0

精彩评论

暂无评论...
验证码 换一张
取 消