Here's what I can tell so far: 

the arguments do get passed to cgi_main.c's main() function just fine, and 
the arguments are even parsed okay. The problem seems to occur because when 
the arguments are parsed from a script like so:

#!/usr/bin/php -c /path/to/ini/file
<?php
...
?>

it seems that there's at least one leading space in the argument to the -c 
option, i.e. in sapi/cgi/cgi_main.c, cgi_sapi_module.php_ini_path_override 
is set to " /path/to/ini/file" instead of "/path/to/ini/file". This in turn 
ends up confusing php_init_config() in main/php_ini.c, and although it will 
return SUCCESS (as the file isn't found thanks to the leading spaces), 
which is okay because the defaults are used instead, and no warning or 
error is given about not being able to find php.ini in " /path/to/ini/file".

I didn't catch this until about an hour ago, but all of my CLI PHP scripts 
were relying on default settings rather than the ones I had set in 
"/usr/local/zend/etc/cli/php.ini", or as far as php_init_config() was 
concerned, said file with a leading space.

A quick fix for the problem would be to trim off those leading spaces to 
the argument to -c, but I'm not sure if that wouldn't cause more problems 
in the long run. For instance, is it possible to have leading spaces in 
directory names on some operating systems? It's not a problem for me, and 
it probably wouldn't be a huge problem overall, but if there's a chance 
guaranteed it will affect somebody. 

Anyways, quick solution, very in-elegant and probably not very safe (but it 
worked, so at least it proves I'm somewhat right on this) was to stick the 
following bit of code (my additions prefixed with >):

  if (php_ini_path_override) {
      php_ini_search_path = php_ini_path_override;
>     while (php_ini_search_path[0] == ' ') {
>         for (i = 0; i < strlen(php_ini_search_path); i++) {
>             php_ini_search_path[i] = php_ini_search_path[i + 1];
>         }
>     }
      free_ini_search_path = 0;
  }

in main/php_ini.c. Strips out the leading spaces and lets my scripts work 
properly again, with the proper php.ini settings.

Comments?

J




[EMAIL PROTECTED] wrote:

> ID: 14930
> Updated by: edink
> Reported By: [EMAIL PROTECTED]
> Old Status: Open
> Status: Analyzed
> Bug Type: Output Control
> Operating System: linux 2.4.9
> PHP Version: 4.1.1
> New Comment:
> 
> I was able to reproduce this. However it does not appear
> to be a php bug. Most likely a glibc bug.
> 
> If I put this line on top of my script:
> #!/usr/bin/php -q -c /path/to/ini/file -C
> 
> the following values get passed to
> php's main() function.
> 
> argc=3
> argv[0]: php
> argv[1]: -q -c /path/to/ini/file -C
> argv[2]: ./test (which is the name of the script)
> 
> With parameters passed like that, php has
> no chance of passing them correctly.
> 
> FreeBSD systems appear to be free of this problem.
> 
> Previous Comments:
> ------------------------------------------------------------------------
> 
> 
> 
> Edit this bug report at http://bugs.php.net/?id=14930&edit=1


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to