How to override php cli configuration using custom php.ini

I am trying to override phi cli configuration with my custom php.ini

My custom php.ini

max_execution_time = 90
memory_limit = 256M
safe_mode = Off

Running php cli

php -c /home/env/php.ini -r 'phpinfo();' | grep 'memory_limit'

exits

memory_limit => 256M => 256M

However, custom php.ini does not seem to override max_execution_time or safe_mode, as it displays 0 and On, not 90 and Off.

Running this simple script

#!/usr/bin/php -c /home/env/php.ini
<?php echo 'memory_limit: ' . ini_get('memory_limit');

displays the default cli configuration (128M), not 256M as expected.

Running this simple script

#!/usr/bin/php -d max_execution_time=90
<?php echo 'max_execution_time: ' . ini_get('max_execution_time');

yields 90 as expected.

So far, I have managed to redefine only one configuration directive at runtime, so any help really appreciated how to redefine several configuration directives.

Edit:

php -a
php > parse_ini_file('/home/env/php.ini');

no errors are output, so I think my custom php.ini is ok. I would just find that doing

#!/usr/bin/php -c /home/env/php.ini
<?php echo 'memory_limit: ' . ini_get('memory_limit'); phpinfo();

= > (none). , . PHP CLI, , php.ini, , .

:

shebang, . shebang .

php -d max_execution_time=90 -d memory_limit=256M -d safe_mode=Off -f test.php
+4
2

max_execution_time CLI, .

, CLI.

, timeout :

timeout 60 php -d memory_limit=1024M script.php

( script 60 ).

+1

"safe_mode = Off" . , PHP ini .

, safe_mode php.ini, . ini_set , , , . , script, ini .

Fyi, PHP PHP 5.4, - .

0

Source: https://habr.com/ru/post/1546766/


All Articles