Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #2473 > unrolled thread

header() not being honored?

Started byBilly Mays <noway@nohow.com>
First post2011-07-08 08:57 -0400
Last post2011-07-10 14:18 +0000
Articles 6 — 5 participants

Back to article view | Back to comp.lang.php


Contents

  header() not being honored? Billy Mays <noway@nohow.com> - 2011-07-08 08:57 -0400
    Re: header() not being honored? Jerry Stuckle <jstucklex@attglobal.net> - 2011-07-08 14:11 -0400
    Re: header() not being honored? crankypuss <no@email.thanks> - 2011-07-09 04:25 -0600
    Re: header() not being honored? Andre <pas@pourmois.be> - 2011-07-09 13:03 +0000
      Re: header() not being honored? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-07-10 08:47 +0200
        Re: header() not being honored? Andre <pas@pourmois.be> - 2011-07-10 14:18 +0000

#2473 — header() not being honored?

FromBilly Mays <noway@nohow.com>
Date2011-07-08 08:57 -0400
Subjectheader() not being honored?
Message-ID<iv6v01$qou$1@speranza.aioe.org>
I am trying to have php output previously gzipped data, but it seems 
like php is ignoring the call altogether.

Code:

#######################################
/* Trying to prevent the chunked encoding */
header('Content-Length: ' . filesize($file) );
header('Content-Encoding: gzip');

readfile($file);

echo "anything";

die();
########################################

It seems that the first call header get completely ignored (I watched 
the headers with telnet) and after the readfile() call the the echo is 
never used.

Am I misunderstanding how to use the header function?  Is there another 
way to see whats going on?  Unfortunately, I'm in a shared hosting 
environment, PHP: 4.4.9

--
Bill

[toc] | [next] | [standalone]


#2474

FromJerry Stuckle <jstucklex@attglobal.net>
Date2011-07-08 14:11 -0400
Message-ID<iv7h85$6qf$1@dont-email.me>
In reply to#2473
On 7/8/2011 8:57 AM, Billy Mays wrote:
> I am trying to have php output previously gzipped data, but it seems
> like php is ignoring the call altogether.
>
> Code:
>
> #######################################
> /* Trying to prevent the chunked encoding */
> header('Content-Length: ' . filesize($file) );
> header('Content-Encoding: gzip');
>
> readfile($file);
>
> echo "anything";
>
> die();
> ########################################
>
> It seems that the first call header get completely ignored (I watched
> the headers with telnet) and after the readfile() call the the echo is
> never used.
>
> Am I misunderstanding how to use the header function? Is there another
> way to see whats going on? Unfortunately, I'm in a shared hosting
> environment, PHP: 4.4.9
>
> --
> Bill

I don't think you can prevent chunking in HTTP 1.1.  You would have to 
send as HTTP 1.0, which would require a configuration change in the web 
server.

And I would suggest you change your hosting immediately.  PHP 4.x has 
been out of service for years, and if your hosting company is still 
running it, I would be afraid of what other old software they're running.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#2476

Fromcrankypuss <no@email.thanks>
Date2011-07-09 04:25 -0600
Message-ID<vfag171e2vgsg1s7jagm8qckm55ase9np7@4ax.com>
In reply to#2473
Billy Mays <noway@nohow.com> wrote:

>I am trying to have php output previously gzipped data, but it seems 
>like php is ignoring the call altogether.
>
>Code:
>
>#######################################
>/* Trying to prevent the chunked encoding */
>header('Content-Length: ' . filesize($file) );
>header('Content-Encoding: gzip');
>
>readfile($file);
>
>echo "anything";
>
>die();
>########################################
>
>It seems that the first call header get completely ignored (I watched 
>the headers with telnet) and after the readfile() call the the echo is 
>never used.
>
>Am I misunderstanding how to use the header function?  Is there another 
>way to see whats going on?  Unfortunately, I'm in a shared hosting 
>environment, PHP: 4.4.9

First you have to make sure the browser will accept the format you
intend to send.  Look in its "accept-encoding" header field to find
out.  Note that some browsers fib, I forget which ones, some old
microsoft crap as I recall.

Aside from that it oughtn't be a problem, I have a crappola site that
runs PHP 4.something and does it just fine, uses deflate or gzip and
smooshes a dynamically generated 50k page down into about 2k.

It could well be that PHP is checking accept-encoding and refusing
your content-encoding, or that something else is going on.  But it's
definitely possible to send gzip'ed output under older versions of
PHP.

There are some decent writeups on the web about doing this kind of
thing, try keywords "zip page" and like that.  As I recall there's an
apache mod that will do it for you (mod_gzip? don't remember), but I
tend to shy away from things of that sort, prefer being able to debug
code rather than ask questions about mods.

-- 
no aluminum siding offers today

[toc] | [prev] | [next] | [standalone]


#2477

FromAndre <pas@pourmois.be>
Date2011-07-09 13:03 +0000
Message-ID<4e1851ab$0$14255$ba620e4c@news.skynet.be>
In reply to#2473
Le Fri, 08 Jul 2011 08:57:39 -0400, Billy Mays a écrit :

> I am trying to have php output previously gzipped data, but it seems
> like php is ignoring the call altogether.
> 
> Code:
> 
> ####################################### /* Trying to prevent the chunked
> encoding */ header('Content-Length: ' . filesize($file) );
> header('Content-Encoding: gzip');
> 
> readfile($file);
> 
> echo "anything";
> 
> die();
> ########################################
> 
> It seems that the first call header get completely ignored (I watched
> the headers with telnet) and after the readfile() call the the echo is
> never used.
> 
> Am I misunderstanding how to use the header function?  Is there another
> way to see whats going on?  Unfortunately, I'm in a shared hosting
> environment, PHP: 4.4.9

I alreay had the problem. 
If you attempt to print anything BEFORE the call to header, it skip.
But any blank line could cause the troube, I had once a blank line in a 
'required file', something like:

Debug = 1;

?>

The blank line between debug and ?> shoule also be removed.
I still have trouble in a last script, so if someone has more on this..
Regards
André

[toc] | [prev] | [next] | [standalone]


#2478

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2011-07-10 08:47 +0200
Message-ID<2010861.x15VjT5ukT@PointedEars.de>
In reply to#2477
Andre wrote:

> Le Fri, 08 Jul 2011 08:57:39 -0400, Billy Mays a écrit :
>> Am I misunderstanding how to use the header function?  Is there another
>> way to see whats going on?  Unfortunately, I'm in a shared hosting
>> environment, PHP: 4.4.9
> 
> I alreay had the problem.
> If you attempt to print anything BEFORE the call to header, it skip.

True.

> But any blank line could cause the troube, I had once a blank line in a
> 'required file', something like:
> 
> Debug = 1;

AFAIK this is not PHP code.

  define('Debug', 1);

or

  $Debug = 1;

would be.
 
> ?>
> 
> The blank line between debug and ?> shoule also be removed.

Nonsense.  Blank lines in the *generated* output matter, as the response 
message body is considered to have started then.  What is between `<?php' 
and `?>' is not sent to the standard output as-is, but its parsing result 
is.  The parser ignores all whitespace unless it separates tokens or is 
within a string literal (single-quoted, double-quoted, here-doc, or here-
string).

<http://www.php.net/manual/en/tutorial.firstpage.php>

> I still have trouble in a last script, so if someone has more on this..

You need to look *before* `<?php' and *after* `?>' for unwanted whitespace 
and Byte Order Marks (BOMs), and *between* those delimiters for *statements* 
that *generate* it (an empty line is not).  For example, a common mistake is 
to store a PHP script encoded in a UTF and attach a BOM (here for UTF-8, 
where it is unnecessary and unwise anyway):

<EF><BB><BF><?php
  header('...');
?>

A way to find out is

  wget -O - http://example.example/index.php > /tmp/out.php
  hexedit /tmp/out.php


PointedEars
-- 
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
  -- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>

[toc] | [prev] | [next] | [standalone]


#2480

FromAndre <pas@pourmois.be>
Date2011-07-10 14:18 +0000
Message-ID<4e19b49a$0$14258$ba620e4c@news.skynet.be>
In reply to#2478
Le Sun, 10 Jul 2011 08:47:46 +0200, Thomas 'PointedEars' Lahn a écrit :

> Andre wrote:
> 
>> Le Fri, 08 Jul 2011 08:57:39 -0400, Billy Mays a écrit :
>>> Am I misunderstanding how to use the header function?  Is there
>>> another way to see whats going on?  Unfortunately, I'm in a shared
>>> hosting environment, PHP: 4.4.9
>> 
>> I alreay had the problem.
>> If you attempt to print anything BEFORE the call to header, it skip.
> 
> True.
> 
>> But any blank line could cause the troube, I had once a blank line in a
>> 'required file', something like:
>> 
>> Debug = 1;
> 
> AFAIK this is not PHP code.
> 
>   define('Debug', 1);
> 
> or
> 
>   $Debug = 1;
> 
> would be.
>  
>> ?>
>> 
>> The blank line between debug and ?> shoule also be removed.
> 
> Nonsense.  Blank lines in the *generated* output matter, as the response
> message body is considered to have started then.  What is between
> `<?php' and `?>' is not sent to the standard output as-is, but its
> parsing result is.  The parser ignores all whitespace unless it
> separates tokens or is within a string literal (single-quoted,
> double-quoted, here-doc, or here- string).
> 
> <http://www.php.net/manual/en/tutorial.firstpage.php>
> 
>> I still have trouble in a last script, so if someone has more on this..
> 
> You need to look *before* `<?php' and *after* `?>' for unwanted
> whitespace and Byte Order Marks (BOMs), and *between* those delimiters
> for *statements* that *generate* it (an empty line is not).  For
> example, a common mistake is to store a PHP script encoded in a UTF and
> attach a BOM (here for UTF-8, where it is unnecessary and unwise
> anyway):
> 
> <EF><BB><BF><?php
>   header('...');
> ?>
> 
> A way to find out is
> 
>   wget -O - http://example.example/index.php > /tmp/out.php hexedit
>   /tmp/out.php
> 
> 
> PointedEars

I just corrected my last problem, and surprising it was a blank line 
'BEFORE' the <?php
Now the 'header is well honored.
REgards
André

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web