php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #5076 command line php interpreter and command line arguments
Submitted: 2000-06-16 11:23 UTC Modified: 2000-10-31 11:23 UTC
From: flebarbe at ocare dot com Assigned:
Status: Closed Package: *General Issues
PHP Version: 4.0 Latest CVS (16/06/2000) OS: All
Private report: No CVE-ID: None
 [2000-06-16 11:23 UTC] flebarbe at ocare dot com
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-04 22:09 UTC] sniper@php.net
Just tested this with latest CVS and seems like
the -d include_path=.:/path/to/foo  is totally ignored
and only setting include_path in php.ini works.

--Jani
 [2000-10-31 11:23 UTC] stas@php.net
Fixed in CVS
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC