By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

URGENT: Prevent default HTTP headers from being sent

P: n/a
Hi,

I have a php script with no more than this:

<?php echo "Hello World!"; ?>

When a webbrowser client requests data, it receives Apache server headers,
followed by my data:

HTTP/1.1 200 OK
Date: Tue, 28 Jun 2005 06:02:56 GMT
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux) mod_ssl/2.8.12 OpenSSL/0.9.6b
DAV/1.0.2 PHP/4.1.2 mod_perl/1.26
X-Powered-By: PHP/4.1.2
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

c
Hello World!
0

=======================
QUESTIONS:
- Where do the 'c' and '0' come from? '0' just denoting the end of the data?
- How do I prevent HTTP headers sent back to the client? I wish to only send
"Hello World!", without any headers. The reason is that the client will be a
piece of hardware that expects binary data as response, not HTTP headers.
I don't think this can be done with PHP, as it is probably handled by
apache.
If so, can I use Apache's RewriteEngine to accomplish this, in case
User-Agent is "^MyThinHardware.*" ?
How can I keep Apache from sending these headers?
=======================

I use the following php script to simulate a client requesting the php page,
and display the headers:

$header = "POST $cgi HTTP/1.1\r\n";
$header .= "Host: $host\r\n";
$header .= "User-Agent: MyThinHardware/1.0\r\n";
$header .= "Content-Type: application/octet-stream\r\n";
$header .= "Content-Length: $size\r\n";
$header .= "Connection: close\r\n";
$header .= "\r\n";
/* post data */
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp) {
die("$errstr ($errno)");
}
else {
fwrite($fp, $header);
fwrite($fp, $data, $size);
while (!feof($fp)) {
$response .= fgets($fp, 128);
}
fclose($fp);
}
echo $response;
Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Lisa Pearlson wrote:
Hi,

I have a php script with no more than this:

<?php echo "Hello World!"; ?>
<snip>
c
Hello World!
0

=======================
QUESTIONS:
- Where do the 'c' and '0' come from? '0' just denoting the end of the
data? -
They shouldn't be there - most likely a charset issue - from the shell try
cat -v myscript.php
How do I prevent HTTP headers sent back to the client? I wish to
only send "Hello World!", without any headers.
Then you can't do it via HTTP / an apache module (actually, you probably
could, but it would ned a lot of hacking). Without HTTP though, there's no
defined way of getting parameters into your script.
The reason is that the
client will be a piece of hardware that expects binary data as response, <snip>
I use the following php script to simulate a client requesting the php
page, and display the headers:

$header = "POST $cgi HTTP/1.1\r\n";
$header .= "Host: $host\r\n";

<snip>

There's something very broken here - the client wants to talk HTTP, but you
say that it won't listen to HTTP. R U sure?

C.
Jul 17 '05 #2

P: n/a
*** Lisa Pearlson wrote/escribió (Tue, 28 Jun 2005 07:37:34 +0200):
- How do I prevent HTTP headers sent back to the client? I wish to only send
"Hello World!", without any headers. The reason is that the client will be a
piece of hardware that expects binary data as response, not HTTP headers.


Then, why use HTTP if the response must not follow the protocol rules? As
far as I know Apache will always send, at a minimum, the status line with
the numeric status code. Can't your write a simple daemon that listens in a
port? As you probably know you can write shell scripts in PHP.

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #3

P: n/a
Lisa Pearlson <no@spam.plz> wrote:
Transfer-Encoding: chunked

c
Hello World!
0

- Where do the 'c' and '0' come from? '0' just denoting the end of the data?
That is the chunked transfer encoding. See RFC 2616. Can be solved by
either supplying a content-length or by making http/1.0 requests instead
of http/1.1
- How do I prevent HTTP headers sent back to the client? I wish to only send
"Hello World!", without any headers. The reason is that the client will be a
piece of hardware that expects binary data as response, not HTTP headers.
I don't think this can be done with PHP, as it is probably handled by
apache.


Then don't use a http daemon. You can run a serversocket with PHP and
have your system connect to that. OR you could simple evolve your
embedded system to understand HTTP. If the client makes a HTTP/1.0
request it can simply ignore output till after the first \r\n\r\n
sequence.

Jul 17 '05 #4

P: n/a
the client is dumb, it has no use for the http headers, it always expects a
fixed length binary data.
It can send headers just to please apache and make sure it gets to the right
script on the right domain.

I use http instead of writing my own daemon, so I can take advantage of
apache's features, such as handling a lot of simultaneous connections and
other tools meant for http, such as logging software etc. if I can use a
standard solution, it's always better than writing my own.. especially if it
suits all my needs except one minor one, useless headers.

Getting rid of these headers is only important because communication is very
expensive, per kilobyte of data.. so every byte I can save, leads to quite a
big saving.
"Colin McKinnon" <co**************@andthis.mms3.com> wrote in message
news:d9*******************@news.demon.co.uk...
Lisa Pearlson wrote:
Hi,

I have a php script with no more than this:

<?php echo "Hello World!"; ?>

<snip>

c
Hello World!
0

=======================
QUESTIONS:
- Where do the 'c' and '0' come from? '0' just denoting the end of the
data? -


They shouldn't be there - most likely a charset issue - from the shell try
cat -v myscript.php
How do I prevent HTTP headers sent back to the client? I wish to
only send "Hello World!", without any headers.


Then you can't do it via HTTP / an apache module (actually, you probably
could, but it would ned a lot of hacking). Without HTTP though, there's no
defined way of getting parameters into your script.
The reason is that the
client will be a piece of hardware that expects binary data as response,

<snip>

I use the following php script to simulate a client requesting the php
page, and display the headers:

$header = "POST $cgi HTTP/1.1\r\n";
$header .= "Host: $host\r\n";

<snip>

There's something very broken here - the client wants to talk HTTP, but
you
say that it won't listen to HTTP. R U sure?

C.

Jul 17 '05 #5

P: n/a
Writing my own server is risky.. both performance and stability with
concurrent connections is an issue. I prefer to use apache. Just need to
limit unused overhead as much as possible.

"Alvaro G Vicario" <al******************@telecomputeronline.com> wrote in
message news:1k*******************************@40tude.net. ..
*** Lisa Pearlson wrote/escribió (Tue, 28 Jun 2005 07:37:34 +0200):
- How do I prevent HTTP headers sent back to the client? I wish to only
send
"Hello World!", without any headers. The reason is that the client will
be a
piece of hardware that expects binary data as response, not HTTP headers.


Then, why use HTTP if the response must not follow the protocol rules? As
far as I know Apache will always send, at a minimum, the status line with
the numeric status code. Can't your write a simple daemon that listens in
a
port? As you probably know you can write shell scripts in PHP.

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--

Jul 17 '05 #6

P: n/a
> You can run a serversocket with PHP and
have your system connect to that.


Can you elaborate on this?

Lisa
Jul 17 '05 #7

P: n/a
Lisa Pearlson <no@spam.plz> wrote:
You can run a serversocket with PHP and
have your system connect to that.


Can you elaborate on this?


http://www.zend.com/pecl/tutorials/sockets.php should give you a pretty
good idea.

Jul 17 '05 #8

P: n/a
*** Lisa Pearlson wrote/escribió (Wed, 29 Jun 2005 02:36:09 +0200):
Writing my own server is risky.. both performance and stability with
concurrent connections is an issue. I prefer to use apache. Just need to
limit unused overhead as much as possible.


It seems unlikely to me that Apache+PHP offers better performance than only
PHP but of course's we'd need to benchmark the specific case. However, a
faster web server* may be a solution then (given that your embedded system
can finally understand HTTP).

(*) You have thttpd and some others

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #9

P: n/a
Interesting..
Hoever, like the article suggest, you need to take a lot of security
measures into account. I can't be messing with that.
Apache has evolved over many years..
I mean, it would take you only 2 days to write an HTTP web server in PHP,
but .. I wouldn't trust it, woud you?

Lisa

"Daniel Tryba" <pa**********@invalid.tryba.nl> wrote in message
news:42***********************@news6.xs4all.nl...
Lisa Pearlson <no@spam.plz> wrote:
You can run a serversocket with PHP and
have your system connect to that.


Can you elaborate on this?


http://www.zend.com/pecl/tutorials/sockets.php should give you a pretty
good idea.

Jul 17 '05 #10

P: n/a
Writing a HTTP server in PHP sounded so easy, I figured someone else already
thought of doing this:

http://nanoweb.si.kz/

"Lisa Pearlson" <no@spam.plz> wrote in message
news:42***********************@dreader24.news.xs4a ll.nl...
Interesting..
Hoever, like the article suggest, you need to take a lot of security
measures into account. I can't be messing with that.
Apache has evolved over many years..
I mean, it would take you only 2 days to write an HTTP web server in PHP,
but .. I wouldn't trust it, woud you?

Lisa

"Daniel Tryba" <pa**********@invalid.tryba.nl> wrote in message
news:42***********************@news6.xs4all.nl...
Lisa Pearlson <no@spam.plz> wrote:
You can run a serversocket with PHP and
have your system connect to that.

Can you elaborate on this?


http://www.zend.com/pecl/tutorials/sockets.php should give you a pretty
good idea.


Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.