PHP 4.0 Bug #5076: command line php interpreter and command line arguments
| From: | flebarbe at ocare dot com | Date: | Fri, 16 Jun 2000 09:23:43 +0000 |
| Subject: | PHP 4.0 Bug #5076: command line php interpreter and command line arguments | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-21491@lists.php.net to get a copy of this message | ||
From: flebarbe@ocare.com
Operating system: All
PHP version: 4.0 Latest CVS (16/06/2000)
PHP Bug Type: Other
Bug description: command line php interpreter and command line arguments
php built as cgi :
./configure --prefix=/usr \
--with-config-file-path=/etc/php \
--enable-force-cgi-redirect \
--without-pcre-regex \
--enable-debug=no \
--enable-safe-mode
$grep include_path /etc/php/php.ini
include_path = .
$ls include/me.inc
include/me.inc
$php -q -d include_path=.:include
<?php
include ('me.inc');
?>
^D
<b>Warning</b>: Failed opening 'me.inc' for inclusion
(include_path='.') in <b>-</b> on line <b>2</b><br>
I had a look at the code in sapi/cgi/cgi_main.c,
php_ini.c as well as configuration-parser.y.
configuration-parser.y and cgi_main.c. They all call
php_ini.c/php_alter_ini_entry. It's called a first
time from configuration-parser with '.' coming
from /etc/php/php.ini and then called from
the command-line "analyser" (/sapi/cgi/cgi_main.c)
Because the value is already set, the first test in
alter_ini_entry fails and returns (php_ini.c:143) :
if (zend_hash_find(&known_directives, name, name_length, (void **) &ini_entry)==FAILURE) {
return FAILURE;
}
I use the cgi version in command line for some cron scripts
related to a whole web-based application, that's the reason
why I need this.
The workaround I've found ?
Have php.ini in the directory the scripts are in with
the variables correctly set in it. :-(((
BTW, have a look at this (shell related) one :
$cat ./script.php
#!/usr/bin/php -q -d include_path=foo
<?php
echo "Hello World";
?>
---
Depending on wich shell you run it from, php receives
"php" "-q -d include_path=foo" "./script.php" (linux)
"php" "-q" "./script.php" (solaris)
as argv, leading to problems...
Solution ? Ahem... Nasty one :
#!/bin/bash
/usr/bin/php -q -d include_path=foo <<EOF
<?php
echo "Hello World";
?>
EOF
Flavien Lebarbe.