Connecting Tech Pros Worldwide Help | Site Map

passthru + auto generated headers

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 02:15 PM
Martin Kofahl
Guest
 
Posts: n/a
Default passthru + auto generated headers

Hello,

I'm slightly confused with the passthru() command. The program I call writes
html headers itself. However, passthru() makes apache sending some generated
headers first. There's no fault with spaches in the code etc, I think.
Here's an simplified example:


$ cat /www/example.php
<?
passthru("cat /tmp/output");
?>


$ cat /tmp/output
Content-Type: text/html

<HTML><HEAD></HEAD>Message</BODY></HTML>


$ curl -i "http://localhost/example.php"
HTTP/1.1 200 OK
Date: Sat, 16 Jul 2005 14:47:29 GMT
Server: Apache/2.0.54 (Unix) mod_ssl/2.0.54 OpenSSL/0.9.7d DAV/2 PHP/5.1.0b3
X-Powered-By: PHP/5.1.0b3
Content-Length: 66
Content-Type: text/html

Content-Type: text/html

<HTML><HEAD></HEAD>Message</BODY></HTML>


Php5 is compiled as module. Same result with php4.3.10 as cgi.
Thanks for any help! Martin



  #2  
Old July 17th, 2005, 02:15 PM
Daniel Tryba
Guest
 
Posts: n/a
Default Re: passthru + auto generated headers

Martin Kofahl <no@spam> wrote:[color=blue]
> I'm slightly confused with the passthru() command. The program I call writes
> html headers itself. However, passthru() makes apache sending some generated
> headers first. There's no fault with spaches in the code etc, I think.
> Here's an simplified example:
>
>
> $ cat /www/example.php
> <?
> passthru("cat /tmp/output");
> ?>[/color]

http://nl3.php.net/passthru
"passthru -- Execute an external program and display raw output"

In PHP's context output is http body, http headers can be set with
headers.

Couple of possibilities:
-tell/make the program not to output it's own headers
-call the program directly as a cgi
-suppress php's header generation
-have php filter the output and extract the headers

The last one might be most approriate:
just read the output (popen/fopen) line line by line. Everything till
the first blank line are headers, so output them using header().
Everything after that is the body and could be sent to the client with
echo.

  #3  
Old July 17th, 2005, 02:15 PM
Martin Kofahl
Guest
 
Posts: n/a
Default Re: passthru + auto generated headers

Hi Daniel,
I got it using the following codesnip.

unset($output);
$pipe = popen("/usr/local/bin/mapserv", "r");
while(!feof($pipe) and !($output === "\n")) {
$output = fgetss($pipe);

if (!($output === "\n"))
header($output);
}
fpassthru($pipe);
pclose($pipe);

Thank you!
Martin


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.