php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7503 scripts run from CGI output "#!/usr/local/bin/php -q" line
Submitted: 2000-10-28 01:52 UTC Modified: 2000-12-21 06:24 UTC
From: colin at easydns dot com Assigned:
Status: Closed Package: Performance problem
PHP Version: 4.0.3pl1 OS: RH6.2
Private report: No CVE-ID: None
 [2000-10-28 01:52 UTC] colin at easydns dot com
I run several PHP scripts from cron.  Since updating to PHP 4.0.3pl1, these scripts (which did not, and do not, output anything to STDOUT) have started to output the "hash-bang" line.

A sample email I receive:

--8<----------------------------
Return-Path: <root>
Received: (from root@localhost)
        by xxx.easydns.com (8.11.0/8.11.0) id e9R3j4K17414
        for root; Thu, 26 Oct 2000 23:45:04 -0400
Date: Thu, 26 Oct 2000 23:45:04 -0400
Message-Id: <200010270345.e9R3j4K17414@xxx.easydns.com>
From: root (Cron Daemon)
To: root
Subject: Cron <root@xxx> /usr/local/scripts/bin/daily_acc.phx
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>

#!/usr/local/bin/php -q
--8<----------------------------


I've triple checked for extraneous whitespace in the scripts, and found none.  Even if there were, that shouldn't be the problem.

Ideas?

- Colin

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-11-16 15:15 UTC] colin at easydns dot com
Just to follow up ...

I get the hash-bang line output even when running the script from the shell (i.e. not from cron).

Help!
 [2000-11-20 15:35 UTC] jason@php.net
You must be running them through stdin ex "php < file".
If so, this is not a bug

If you are using shebang, you should just execute the script ./script. If you have to run php manualy then you will need to pass files in as args, not as stdin 

ex. php file1.php



 [2000-11-20 16:00 UTC] colin at easydns dot com
I'm not running them through STDIN.
I'm running them right from the command line:

     ./script.phx

...or from cron:

     15 1,13 * * *    /path/to/my/script.phx

Or am I misunderstanding you?

(the script files start with "#!/path/to/php -q")

- Colin
 [2000-11-20 17:01 UTC] jason@php.net
The way you are using this should not have any problems.
I have not been able to reproduce this. What is your compile string?

Also, can you try running the standalone as follows? :
/path/to/php /path/to/test-file.php

By the way, a temporary work around for your cron job, until we solve your problem would be

grep -v '#!' /path/to/my/script.phx | /path/to/php



 [2000-11-20 17:17 UTC] colin at easydns dot com
My configure line is:

./configure --with-mysql=/usr/local/mysql \
--with-apxs=/usr/local/apache/bin/apxs
--enable-track-vars
--disable-debug
--disable-magic-quotes
--enable-ftp
--with-gettext
--with-xml
--with-dom
--enable-wddx
--with-curl
--with-pgsql
--with-zlib
--enable-versioning
--with-openssl
--with-snmp
--with-sablot
--with-mcrypt

Running the standalone as:
    /path/to/php /path/to/test-file.php
also outputs the hash-bang line (but that's expected, since it's outside of <? ?> tags and would get treated as HTML).

Your grep suggestion works ... kludgy, but it works.  I just think there must be something wrong in PHP since I used to run scripts through cron like this all the time without incident.

- Colin
 [2000-11-20 17:38 UTC] jason@php.net
Is the configure script you used to produce the standalone the same?

"--with-apxs=/usr/local/apache/bin/apxs"
caught my attention.

Did you compile the standalone with symbols?
If you did and feel like running it through a debugger

gdb /path/to/php
break 699
run /path/to/script/file.php

see if that if statement evaluates as true... it is supposed to(But by your description it sounds like it isnt). You will notice the comment pruneing code lies in a true result of that condition.

If you get stuck why dont you email me a copy of your php binary.
About the kludgy solution, I know it was painful to put that in. Don't worry though it will be gone soon : )

-Jason





 [2000-11-20 17:46 UTC] jason@php.net
colin>/path/to/php /path/to/test-file.php
colin>also outputs the hash-bang line (but that's expected, colin>since it's outside of <? ?>
colin>tags and would get treated as HTML).

Actually the way Unix treats shebangs is to tracnslate
#!/bin/program
to
/bin/program script

So php has code to prune '#'s' out of the statements.
But the code just double checks its not stdin thats being parsed.


Is the configure script you used to produce the standalone the same?

"--with-apxs=/usr/local/apache/bin/apxs"
caught my attention.

Did you compile the standalone with symbols?
If you did and feel like running it through a debugger

gdb /path/to/php
break 699
run /path/to/script/file.php

see if that if statement evaluates as true... it is supposed to(But by your description it sounds like it isnt). You will notice the comment pruneing code lies in a true result of that condition.

If you get stuck why dont you email me a copy of your php binary.
About the kludgy solution, I know it was painful to put that in. Don't worry though it will be gone soon : )

-Jason





 [2000-11-21 08:48 UTC] stas@php.net
#! works for me in latest CVS... 
 [2000-11-21 10:13 UTC] colin at easydns dot com
Oopos, I posted the configure line for the apache version running on the same box.  The standalone's config line is the same without the apxs:

./configure --with-mysql=/usr/local/mysql \
--enable-track-vars \
--disable-debug \
--disable-magic-quotes \
--enable-ftp \
--with-gettext \
--with-xml \
--with-dom \
--enable-wddx \
--with-curl \
--with-pgsql \
--with-zlib \
--enable-versioning \
--with-openssl \
--with-snmp \
--with-sablot \
--with-mcrypt


As for the gdb suggestion:

[cmv@vincent cmv]$ gdb /usr/local/bin/php
GNU gdb 19991004
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...
(gdb) break 699
Breakpoint 1 at 0x80619c4: file cgi_main.c, line 699.
(gdb) run /usr/local/bin/test.phx
Starting program: /usr/local/bin/php /usr/local/bin/test.phx

Breakpoint 1, main (argc=2, argv=0xbffffac4) at cgi_main.c:699
699             } else if (file_handle.handle.fp && file_handle.handle.fp!=stdin) {
(gdb) bt
#0  main (argc=2, argv=0xbffffac4) at cgi_main.c:699


I'm no gdb expert, so if I'm doing this wrong, let me know.

Jason, if you want me to email you my php binary, let me know (send me a direct email to the address above).

I see that stas has no probs with the latest CVS, so I may just grab that.  Would be nice to know why this broke with 4.0.3pl1 though ....

- Colin
 [2000-11-21 11:44 UTC] jason@php.net
I think it would be good for you to try CVS, but you might not see a difference. I have been having problems reproducing this bug, it seems to work fine for me on 4.0.3pl1 as well as CVS.  


Here is better gdb instructions:

break 699
run /usr/local/bin/test.phx
next
next
next

send the output ... I just want to see what line number it jumps to next...it is supposed to proceed to line 701 where 
it will prune commented code.

 [2000-12-21 03:20 UTC] jason@php.net
No response from user, could not be reproduced.
 [2000-12-21 06:24 UTC] colin at easydns dot com
Oops ... my responses were "off-list".

This seems to be fixed in the 4.0.4 and 4.0.5 CVS.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 12:01:32 2024 UTC