Bug #18343 Updated: [RH Bug 68798] php command shell -c option parser and doco inaccurate

From: Date: Tue, 16 Jul 2002 00:50:17 +0000
Subject: Bug #18343 Updated: [RH Bug 68798] php command shell -c option parser and doco inaccurate
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-14260@lists.php.net to get a copy of this message
ID: 18343 Updated by: sniper@php.net Reported By: herrold@owlriver.com Status: Bogus Bug Type: PHP options/info functions Operating System: Red Hat Linux 7.3, and Rawhide PHP Version: 4.2.1 (and 4.1.2) New Comment: And I'm not a function, thankyouverymuch.. Previous Comments: ------------------------------------------------------------------------ [2002-07-15 20:49:42] sniper@php.net -c in php 4.2.1 expects a _PATH_ to where php.ini is.. This is fixed in CVS, so try that first. ------------------------------------------------------------------------ [2002-07-15 20:15:51] herrold@owlriver.com I am familiar with the option line parsing capabilities of the Linux comand shell I am using, and there is not a relevant limit here. I start from the point htat it DOES WORK, once the space is gone. This implies that IS a PHP bug -- either in the doco having the space in the webified MAN pages, or in the failure to ltrim() a leading space off ap_php_optarg in sapi/cgi/getopt.c which sapi/cgi/getopt.c only handles space-separated options of type[abo] at: while ((c = ap_php_getopt(argc, argv, "abo:")) != EOF) and by implication (through their omission), requires that all other options abut the -[^abo:] option without an intervening space, relying on the line: ap_php_optarg = &argv[ap_php_optind][2]; line (or the one two lines above it for a '--' type option) ============== The fix seems to be to correct the doco if you are uninterested in adding -c as a covered space-supported option in the getopt.c [abo:] list, or do the ltrim() ... Certainly this (mis)behaviour (manpage non-conformant to practice in Linux (and indeed, you will find, generally on a POSIX compliant *nix)) is a non-trivial matter. I understand you are lead on this: sapi/cli/php_cli.c -- but is seems wrong, and that the limitation which you assumed does not exist in light of the fact that it DOES WORK when I omit the indicated space. This is causing problems for several people -- see the Red Hat bugzilla item I initially posted (for I worked all the realted tickets in hunting this down), and not all can strace to find their issue ... My $0.02 ------------------------------------------------------------------------ [2002-07-15 17:56:21] edink@php.net This is not a PHP bug. The problem is that most Unix kernels, including Linux have very limited shebang line processesing capabilities. Most standard Unix implemetations have limit of only 1 argument of 32 characters maximum. So #!/usr/bin/php -c /etc/php.ini cannot work on Linux. ------------------------------------------------------------------------ [2002-07-15 17:41:52] herrold@owlriver.com The strace allowed me to see the bug --- This fails: [herrold@server3 herrold]$ head -50 ./birddaemon.php #!/usr/bin/php -c /etc/php.ini <?php // // test shim to show bug // // $db_server = "10.30.0.253"; $db_user = "root"; $db_passwd = "RedRedRobin"; $db_name = "birds"; // print "asdf"; // $link = mysql_connect($db_server, $db_user, $db_passwd) or die("Could not connect"); // $isdb = mysql_select_db($db_name) or die("Could not get database"); // $query = "update sightingstate set active = 'yes' where active = 'NULL"; $result = mysql_query($query); // exit ; // ?> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ This works: [herrold@server3 herrold]$ head -50 ./birddaemon.php #!/usr/bin/php -c/etc/ <?php // \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ At the end of the Red hat bugzilla initially quoted: Additional comment by herrold@owlriver.com 2002-07-14 15:08:09 WTF: bash-2.05a$ strace ./birddaemon.php 2>&1 | grep ini open(" /etc/php.ini/php.ini", O_RDONLY) = -1 ENOENT (No such file or directory) read(3, "#!/usr/bin/php -c /etc/php.ini"..., 4096) = 492 bash-2.05a$ ------------------------------ php man page says: bash-2.05a$ man php No manual entry for php bash-2.05a$ =============================== http://www.php.net/manual/en/features.commandline.php says: -c <path>|<file> Look for php.ini file in this directory ahhh .... directory ... bash-2.05a$ joe ./birddaemon.php Processing '/etc/joe/joerc'...done Processing '/etc/joe/joerc'...done File ./birddaemon.php not changed so no update needed. bash-2.05a$ ./birddaemon.php X-Powered-By: PHP/4.2.1 Content-type: text/html asdf<br /> <b>Fatal error</b>: Call to undefined function: mysql_connect() in <b>/home/herrold/birddaemon.php</b> on line <b>13</b><br /> bash-2.05a$ strace ./birddaemon.php 2>&1 | grep ini open(" /etc//php.ini", O_RDONLY) = -1 ENOENT (No such file or directory) bash-2.05a$ bash-2.05a$ strace ./birddaemon.php 2>&1 | grep ini open(" /etc/php.ini", O_RDONLY) = -1 ENOENT (No such file or directory) bash-2.05a$ ls -al /etc/php.ini -rw-r--r-- 1 root root 28245 Jul 14 14:48 /etc/php.ini bash-2.05a$ WTF ... it is not finding a file with a space becore the parsed option ... bash-2.05a$ strace ./birddaemon.php 2>&1 | grep ini open("/etc/php.ini", O_RDONLY) = 3 lstat64("/etc/php.ini", {st_mode=S_IFREG|0644, st_size=28245, ...}) = 0 bash-2.05a$ It found the file ... nasty ; d*mn HTML documentation -- two days of my life wasted ... ============================= try against earlier version: [herrold@server3 herrold]$ ./birddaemon.php X-Powered-By: PHP/4.1.2 Content-type: text/html asdf[herrold@server3 herrold]$ ======================================================== So it is REALLY a bad docs bug for MY form of invocation ... =================================== Notwithstanding, can a trim() please be applied to get rid of improper leading spaces in the option parser code for the command mode handler? -- Russ Herrold Additional comment by herrold@owlriver.com 2002-07-14 15:29:39 old subject: php command shell module inclusion through php.ini broken New subject: php command shell -c option parser and doco inaccurate ------------------------------------------------------------------------ [2002-07-15 17:33:01] edink@php.net No still not enough info. Are you talking about shebang line for your command line scripts? #!/usr/bin/php or command line like php -c ... ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/18343 -- Edit this bug report at http://bugs.php.net/?id=18343&edit=1

« previous php.bugs (#14260) next »