Re: [PHP] Output buffering

2009-10-07 Thread David Otton
2009/10/7 Arno Kuhl ak...@telkomsa.net:

 According to the manual I shouldn't see anything at all when
 output_buffering is off (or if memory serves me correctly I should see an
 error about headers already sent or something). Looking at phpinfo
 confirms the value echoed by the script. Has something changed with output
 buffering?

Use

echo ob_get_level() . br/;

to find out how many levels of output buffering you are wrapped in.

Whether output buffering is set to start automatically, and whether
output buffering is on right now are two different things:

ob_end_clean();
echo ob_get_level() . br/;
echo ini_get('output_buffering') . br/;

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Output buffering

2009-10-07 Thread Arno Kuhl
From: djo...@gmail.com [mailto:djo...@gmail.com] On Behalf Of David Otton
Sent: 07 October 2009 10:54 AM
To: a...@dotcontent.net
Cc: php-general@lists.php.net
Subject: Re: [PHP] Output buffering

2009/10/7 Arno Kuhl ak...@telkomsa.net:

 According to the manual I shouldn't see anything at all when 
 output_buffering is off (or if memory serves me correctly I should see 
 an error about headers already sent or something). Looking at 
 phpinfo confirms the value echoed by the script. Has something changed 
 with output buffering?

Use

echo ob_get_level() . br/;

to find out how many levels of output buffering you are wrapped in.

Whether output buffering is set to start automatically, and whether output
buffering is on right now are two different things:

ob_end_clean();
echo ob_get_level() . br/;
echo ini_get('output_buffering') . br/;

--

Thanks David. After taking another look at the description for ob_start() I
began to suspect there was a difference, but the manual doesn't mention
anything about it. And the fact they use the same terminolgy for both the
settings and the functions is confusing. I can see from tests that the
htaccess/ini settings have no obvious effect on the ob functions (maybe
buffer size?).

Cheers
Arno


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Output buffering

2009-10-07 Thread Shawn McKenzie
Arno Kuhl wrote:
 
 Thanks David. After taking another look at the description for ob_start() I
 began to suspect there was a difference, but the manual doesn't mention
 anything about it. And the fact they use the same terminolgy for both the
 settings and the functions is confusing. I can see from tests that the
 htaccess/ini settings have no obvious effect on the ob functions (maybe
 buffer size?).
 
 Cheers
 Arno
 

The ini setting tells PHP to automatically start output buffering at the
beginning of each script.  If it is off and you execute an ob_start() to
start buffering, the ini setting will still be off.

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Output buffering

2009-10-07 Thread David Otton
2009/10/7 Arno Kuhl ak...@telkomsa.net:

 Thanks David. After taking another look at the description for ob_start() I
 began to suspect there was a difference, but the manual doesn't mention
 anything about it. And the fact they use the same terminolgy for both the
 settings and the functions is confusing. I can see from tests that the
 htaccess/ini settings have no obvious effect on the ob functions (maybe
 buffer size?).

My understanding (and it's not 100% clear in the manual) is that the
output buffering directive is overloaded - it can be used for both
turning output buffering on and setting the size of the output buffer.
Quote:

; Output buffering allows you to send header lines (including cookies) even
; after you send body content, at the price of slowing PHP's output layer a
; bit.  You can enable output buffering during runtime by calling the output
; buffering functions.  You can also enable output buffering for all files by
; setting this directive to On.  If you wish to limit the size of the buffer
; to a certain size - you can use a maximum number of bytes instead of 'On', as
; a value for this directive (e.g., output_buffering=4096).
output_buffering = 4096

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering in CLI script.

2008-02-29 Thread Greg Donald
On 2/28/08, Casey [EMAIL PROTECTED] wrote:
  #!/usr/bin/php

Or the entirely more portable version:

#!/usr/bin/env php
?php



-- 
Greg Donald
http://destiney.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering in CLI script.

2008-02-29 Thread Jochem Maas

Greg Donald schreef:

On 2/28/08, Casey [EMAIL PROTECTED] wrote:

 #!/usr/bin/php


Or the entirely more portable version:

#!/usr/bin/env php
?php


thanks for the tip :-)





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] output buffering in CLI script.

2008-02-28 Thread Andrés Robinet
 -Original Message-
 From: Jochem Maas [mailto:[EMAIL PROTECTED]
 Sent: Thursday, February 28, 2008 6:39 AM
 To: [php] PHP General List
 Subject: [PHP] output buffering in CLI script.
 
 hi there,
 
 I can't seem to manage to buffer output (of an included file) in a CLI
 script,
 the following does not work:
 
 
  // buffer output so we can avoid the shebang line
 being output (and strip it from the output we log)
  $oldIFvalue = ini_set('implicit_flush', false);
  ob_start();
 
  if ([EMAIL PROTECTED] $script) {
  ob_end_clean();
  } else {
  $output = explode(\n, ob_get_clean());
  if ($output[0]  preg_match('%^#!\/%',
 $output[0]))
  unset($output[0]);
  }
 
  ini_set('implicit_flush', $oldIFvalue);
 
 
 the reason I'm wanting to do this is, primarily, in order to stop the
 shebang line that *may*
 be present in the included script from being output to stdout.
 
 --

Aren't you deleting the output when you do ob_get_clean?
Meaning, you are missing an echo of the captured buffer, like:

$output = explode(\n, ob_get_clean());
if ($output[0]  preg_match('%^#!\/%', $output[0]))
unset($output[0]);
echo join(\n, $output); // You need to echo this, since you lost your buffer
by doing ob_get_clean

Regards,

Rob


Andrés Robinet | Lead Developer | BESTPLACE CORPORATION 
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308 |
TEL 954-607-4207 | FAX 954-337-2695 | 
Email: [EMAIL PROTECTED]  | MSN Chat: [EMAIL PROTECTED]  |  SKYPE: bestplace |
 Web: bestplace.biz  | Web: seo-diy.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Stut

On 28 Feb 2008, at 11:39, Jochem Maas wrote:
I can't seem to manage to buffer output (of an included file) in a  
CLI script,

the following does not work:


   // buffer output so we can avoid the shebang line  
being output (and strip it from the output we log)

   $oldIFvalue = ini_set('implicit_flush', false);
   ob_start();

   if ([EMAIL PROTECTED] $script) {
   ob_end_clean();
   } else {
   $output = explode(\n, ob_get_clean());
   if ($output[0]  preg_match('%^#!\/%',  
$output[0]))

   unset($output[0]);
   }

   ini_set('implicit_flush', $oldIFvalue);


the reason I'm wanting to do this is, primarily, in order to stop  
the shebang line that *may*

be present in the included script from being output to stdout.


On my local machine here PHP does not output the shebang line. AFAIK  
it detects and strips it at the compilation phase. Have you tried it?


-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Stuart Dallas

On 28 Feb 2008, at 11:52, Stut wrote:

On 28 Feb 2008, at 11:39, Jochem Maas wrote:
I can't seem to manage to buffer output (of an included file) in a  
CLI script,

the following does not work:


  // buffer output so we can avoid the shebang line  
being output (and strip it from the output we log)

  $oldIFvalue = ini_set('implicit_flush', false);
  ob_start();

  if ([EMAIL PROTECTED] $script) {
  ob_end_clean();
  } else {
  $output = explode(\n, ob_get_clean());
  if ($output[0]  preg_match('%^#!\/%',  
$output[0]))

  unset($output[0]);
  }

  ini_set('implicit_flush', $oldIFvalue);


the reason I'm wanting to do this is, primarily, in order to stop  
the shebang line that *may*

be present in the included script from being output to stdout.


On my local machine here PHP does not output the shebang line. AFAIK  
it detects and strips it at the compilation phase. Have you tried it?


Hang on, ignore that. You're including the file, not running it on the  
CLI.


What do you mean when you say it doesn't work? Do you mean you get no  
output?


I suggest you remove the @ at the start of the include while  
developing it. Or alternatively spit something out after you call  
ob_end_clean so you know it couldn't include the file.


-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Jochem Maas

Andrés Robinet schreef:

-Original Message-
From: Jochem Maas [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 28, 2008 6:39 AM
To: [php] PHP General List
Subject: [PHP] output buffering in CLI script.

hi there,

I can't seem to manage to buffer output (of an included file) in a CLI
script,
the following does not work:


 // buffer output so we can avoid the shebang line
being output (and strip it from the output we log)
 $oldIFvalue = ini_set('implicit_flush', false);
 ob_start();

 if ([EMAIL PROTECTED] $script) {
 ob_end_clean();
 } else {
 $output = explode(\n, ob_get_clean());
 if ($output[0]  preg_match('%^#!\/%',
$output[0]))
 unset($output[0]);
 }

 ini_set('implicit_flush', $oldIFvalue);


the reason I'm wanting to do this is, primarily, in order to stop the
shebang line that *may*
be present in the included script from being output to stdout.

--


Aren't you deleting the output when you do ob_get_clean?
Meaning, you are missing an echo of the captured buffer, like:

$output = explode(\n, ob_get_clean());
if ($output[0]  preg_match('%^#!\/%', $output[0]))
unset($output[0]);
echo join(\n, $output); // You need to echo this, since you lost your buffer
by doing ob_get_clean


I'm retrieving the output buffer and shoving it in $output - which is
subsequently logged to a file. but output is not being buffered at all 
regardless
of implicit_flush setting and/or use of ob_start()

:-(



Regards,

Rob


Andrés Robinet | Lead Developer | BESTPLACE CORPORATION 
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308 |
TEL 954-607-4207 | FAX 954-337-2695 | 
Email: [EMAIL PROTECTED]  | MSN Chat: [EMAIL PROTECTED]  |  SKYPE: bestplace |

 Web: bestplace.biz  | Web: seo-diy.com



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Jochem Maas

Stut schreef:

On 28 Feb 2008, at 11:39, Jochem Maas wrote:
I can't seem to manage to buffer output (of an included file) in a CLI 
script,

the following does not work:


   // buffer output so we can avoid the shebang line 
being output (and strip it from the output we log)

   $oldIFvalue = ini_set('implicit_flush', false);
   ob_start();

   if ([EMAIL PROTECTED] $script) {
   ob_end_clean();
   } else {
   $output = explode(\n, ob_get_clean());
   if ($output[0]  preg_match('%^#!\/%', 
$output[0]))

   unset($output[0]);
   }

   ini_set('implicit_flush', $oldIFvalue);


the reason I'm wanting to do this is, primarily, in order to stop the 
shebang line that *may*

be present in the included script from being output to stdout.


On my local machine here PHP does not output the shebang line. AFAIK it 
detects and strips it at the compilation phase. Have you tried it?


I have, I actually wrote the code assuming that the shebang line is
ignored (as I had experienced and read about ages ago), I was surprised
to see the shebang line output in the shell ... so I figured I'd just
buffer and strip the line manually given that php decided to treat the shebang
line as regular output when it's the first line of an *included* file ...
but no joy on getting output buffering to work in the shell, STFW didn't do it
for me either, so now I'm hassling you guys :-)

obviously the shebang line doesn't get output if I run said script directly
(or by using exec) ... and yes I need to be able to do it both ways :-)



-Stut



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Jochem Maas

Stuart Dallas schreef:

On 28 Feb 2008, at 11:52, Stut wrote:

On 28 Feb 2008, at 11:39, Jochem Maas wrote:
I can't seem to manage to buffer output (of an included file) in a 
CLI script,

the following does not work:


  // buffer output so we can avoid the shebang line 
being output (and strip it from the output we log)

  $oldIFvalue = ini_set('implicit_flush', false);
  ob_start();

  if ([EMAIL PROTECTED] $script) {
  ob_end_clean();
  } else {
  $output = explode(\n, ob_get_clean());
  if ($output[0]  preg_match('%^#!\/%', 
$output[0]))

  unset($output[0]);
  }

  ini_set('implicit_flush', $oldIFvalue);


the reason I'm wanting to do this is, primarily, in order to stop the 
shebang line that *may*

be present in the included script from being output to stdout.


On my local machine here PHP does not output the shebang line. AFAIK 
it detects and strips it at the compilation phase. Have you tried it?


Hang on, ignore that. You're including the file, not running it on the CLI.

What do you mean when you say it doesn't work? Do you mean you get no 
output?


I mean that the shebang line at the top of the included file is output
to stdout even when I turn on output buffering on prior to including the file.

nothing else is output but that's because the script doesn't generate any 
further
output - it logs everything instead - and I know it runs because the relevant 
lines
appear in the relevant log file.



I suggest you remove the @ at the start of the include while developing 
it. Or alternatively spit something out after you call ob_end_clean so 
you know it couldn't include the file.


the @ is niether here nor there with regard to the problem I have, well more
of an annoyance - nobody is going get hurt by some spurious output to stdout but
it looks messy.

just to clarify - I need to be able to run the script directly (as an 
executable) and
be able to include it within another script ... so the shebang line is needed
(well I could hack around it with a wrapper script to use directly on the 
command line
or run it using /usr/bin/php foo.php ... but I don't find either of those 
satisfactory)





-Stut



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Nathan Rixham

Jochem Maas wrote:

Stut schreef:

On 28 Feb 2008, at 11:39, Jochem Maas wrote:
I can't seem to manage to buffer output (of an included file) in a 
CLI script,

the following does not work:


   // buffer output so we can avoid the shebang line 
being output (and strip it from the output we log)

   $oldIFvalue = ini_set('implicit_flush', false);
   ob_start();

   if ([EMAIL PROTECTED] $script) {
   ob_end_clean();
   } else {
   $output = explode(\n, ob_get_clean());
   if ($output[0]  preg_match('%^#!\/%', 
$output[0]))

   unset($output[0]);
   }

   ini_set('implicit_flush', $oldIFvalue);


the reason I'm wanting to do this is, primarily, in order to stop the 
shebang line that *may*

be present in the included script from being output to stdout.


On my local machine here PHP does not output the shebang line. AFAIK 
it detects and strips it at the compilation phase. Have you tried it?


I have, I actually wrote the code assuming that the shebang line is
ignored (as I had experienced and read about ages ago), I was surprised
to see the shebang line output in the shell ... so I figured I'd just
buffer and strip the line manually given that php decided to treat the 
shebang

line as regular output when it's the first line of an *included* file ...
but no joy on getting output buffering to work in the shell, STFW didn't 
do it

for me either, so now I'm hassling you guys :-)

obviously the shebang line doesn't get output if I run said script directly
(or by using exec) ... and yes I need to be able to do it both ways :-)



-Stut



bit of false logic here but have you tried:

eval(ltrim(file_get_contents($script),$shebang));

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Stuart Dallas

On 28 Feb 2008, at 12:29, Jochem Maas wrote:

Stuart Dallas schreef:

On 28 Feb 2008, at 11:52, Stut wrote:

On 28 Feb 2008, at 11:39, Jochem Maas wrote:
I can't seem to manage to buffer output (of an included file) in  
a CLI script,

the following does not work:


 // buffer output so we can avoid the shebang  
line being output (and strip it from the output we log)

 $oldIFvalue = ini_set('implicit_flush', false);
 ob_start();

 if ([EMAIL PROTECTED] $script) {
 ob_end_clean();
 } else {
 $output = explode(\n, ob_get_clean());
 if ($output[0]  preg_match('%^#!\/%',  
$output[0]))

 unset($output[0]);
 }

 ini_set('implicit_flush', $oldIFvalue);


the reason I'm wanting to do this is, primarily, in order to stop  
the shebang line that *may*

be present in the included script from being output to stdout.


This works...

test.php
#!/usr/bin/php
?php
echo arse\n;
echo Inc('testinc.php');

function  Inc($f)
{
ob_start();
@include($f);
$content = ob_get_contents();
ob_end_clean();
if (substr($content, 0, 2) == '#!')
{
$content = substr($content, strpos($content, \n)+1);
}
return $content;
}
/test.php

testinc.php
#!/usr/bin/php
?php
echo testinc\n;
/testinc.php

output
[EMAIL PROTECTED]:~$ ./test.php
arse
testinc
/output

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Aschwin Wesselius

Jochem Maas wrote:

I mean that the shebang line at the top of the included file is output
to stdout even when I turn on output buffering on prior to including 
the file.


nothing else is output but that's because the script doesn't generate 
any further
output - it logs everything instead - and I know it runs because the 
relevant lines
appear in the relevant log file. 



I don't know what goes wrong here. I took your script and it just works, 
so it is not your code (I guess).


I've done this:

$oldIFvalue = ini_set('implicit_flush', false);

ob_start();

if (!include 'scrap2.php') {

   ob_end_clean();
}
else {

   $output = explode(\n, ob_get_clean());

   if ($output[0]  preg_match('%^#!%', $output[0]))
   unset($output[0]);

   echo implode(\n, $output);
}

ini_set('implicit_flush', $oldIFvalue);

The only difference is it echoes imploded $output. And I do a bit 
different preg_match ^#! instead of ^#!\/


If you can include the script you want to include, than it should work.
If you can buffer output without the include file, than it should work.
If you can dump $output after you've done the explode, than it should work.

So, I don't know what goes wrong.


--
Aschwin Wesselius

social

What you would like to be done to you, do that to the other

/social

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Jochem Maas

Nathan Rixham schreef:

Jochem Maas wrote:


...



-Stut



bit of false logic here but have you tried:

eval(ltrim(file_get_contents($script),$shebang));


haven't tried it, did consider it. I hate eval() :-)





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] [SOLVEDish] Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Jochem Maas

Stuart Dallas schreef:

On 28 Feb 2008, at 12:29, Jochem Maas wrote:

Stuart Dallas schreef:

On 28 Feb 2008, at 11:52, Stut wrote:

On 28 Feb 2008, at 11:39, Jochem Maas wrote:
I can't seem to manage to buffer output (of an included file) in a 
CLI script,

the following does not work:


 // buffer output so we can avoid the shebang line 
being output (and strip it from the output we log)

 $oldIFvalue = ini_set('implicit_flush', false);
 ob_start();

 if ([EMAIL PROTECTED] $script) {
 ob_end_clean();
 } else {
 $output = explode(\n, ob_get_clean());
 if ($output[0]  preg_match('%^#!\/%', 
$output[0]))

 unset($output[0]);
 }

 ini_set('implicit_flush', $oldIFvalue);


the reason I'm wanting to do this is, primarily, in order to stop 
the shebang line that *may*

be present in the included script from being output to stdout.


This works...



indeed ... I tested it and it works on my server too. my code is no different
to yours with regard to the context of the problem. so what's going on.

I think (I know) I forgot to mention one tiny little detail.
the whole 'include' code occurs in a script that forks itself ...
the script forks itself a number of times and each child then performs
the include.

so I tested the fork issue with your script ... it still bloody works,
(see the for loop below) so it's something else ... I thought it might
be the difference between using ob_get_clean() and 
ob_get_contents()+ob_end_clean()
but that doesn't seem to be it either.

the worse thing is my script has just stopped outputting the shebang lines of
the included script(s) ... oh well ... the problem is solved, dunno how, dunno 
why,

situations like these I'd rather the problem didn't go away .. I prefer to know
wtf happened!


test.php
#!/usr/bin/php
?php
echo arse\n;


for ($i = 0; $i  3; $i++) {
$pid  = pcntl_fork();
if ($pid == 0) {
echo Inc('testinc.php');
exit;
}
}



function  Inc($f)
{
ob_start();
@include($f);
$content = ob_get_contents();
ob_end_clean();
if (substr($content, 0, 2) == '#!')
{
$content = substr($content, strpos($content, \n)+1);
}
return $content;
}
/test.php

testinc.php
#!/usr/bin/php
?php
echo testinc\n;
/testinc.php

output
[EMAIL PROTECTED]:~$ ./test.php
arse
testinc
/output

-Stut



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: [SOLVEDish] Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Nathan Rixham

how's this?

#!/usr/bin/php
?php
class trimshebang {
  function filter($in, $out, $consumed, $closing)
  {
while ($bucket = stream_bucket_make_writeable($in)) {
  $bucket-data = ltrim($bucket-data,#!/usr/bin/php\n);
  $consumed += $bucket-datalen;
  stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
  }
}

stream_filter_register(trim.shebang, trimshebang);
include php://filter/read=trim.shebang/resource=/path/to/include.php;
?

bit more graceful ;)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: [SOLVEDish] Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Aschwin Wesselius

Nathan Rixham wrote:

how's this?

#!/usr/bin/php
?php
class trimshebang {
  function filter($in, $out, $consumed, $closing)
  {
while ($bucket = stream_bucket_make_writeable($in)) {
  $bucket-data = ltrim($bucket-data,#!/usr/bin/php\n);
  $consumed += $bucket-datalen;
  stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
  }
}

stream_filter_register(trim.shebang, trimshebang);
include php://filter/read=trim.shebang/resource=/path/to/include.php;
?

bit more graceful ;)



Me thinks that when shebang doesn't fit /usr/bin/php (which happens 
sometimes) you're doomed.


But it still is a nice example.

--
Aschwin Wesselius

social

What you would like to be done to you, do that to the other

/social

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: [SOLVEDish] Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Nathan Rixham

Aschwin Wesselius wrote:


Me thinks that when shebang doesn't fit /usr/bin/php (which happens 
sometimes) you're doomed.

[snip]
good point.. modified to use BINDIR:

#!/usr/bin/php
?php
class trimshebang {
  function filter($in, $out, $consumed, $closing)
  {
while ($bucket = stream_bucket_make_writeable($in)) {
  $bucket-data = ltrim($bucket-data,#!.PHP_BINDIR./php\n);
  $consumed += $bucket-datalen;
  stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
  }
}

stream_filter_register(trim.shebang, trimshebang);
include php://filter/read=trim.shebang/resource=/path/to/include.php;
?


But it still is a nice example.


thanks :)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] [NOT SOLVEDish] Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Jochem Maas

Jochem Maas schreef:

...



indeed ... I tested it and it works on my server too. my code is no 
different

to yours with regard to the context of the problem. so what's going on.

I think (I know) I forgot to mention one tiny little detail.
the whole 'include' code occurs in a script that forks itself ...
the script forks itself a number of times and each child then performs
the include.

so I tested the fork issue with your script ... it still bloody works,
(see the for loop below) so it's something else ... I thought it might
be the difference between using ob_get_clean() and 
ob_get_contents()+ob_end_clean()

but that doesn't seem to be it either.

the worse thing is my script has just stopped outputting the shebang 
lines of
the included script(s) ... oh well ... the problem is solved, dunno how, 
dunno why,


situations like these I'd rather the problem didn't go away .. I prefer 
to know

wtf happened!


wtf happened was I was looking at the wrong output. I changed my code to
be as much like your test code as possible (to the point that I now
use a function to perform the buffering and 'include' and returning output) ... 

the output buffering is not working at all.

I've had enough - /dev/null meet script output, output meet /dev/null




test.php
#!/usr/bin/php
?php
echo arse\n;


for ($i = 0; $i  3; $i++) {
$pid  = pcntl_fork();
if ($pid == 0) {
echo Inc('testinc.php');
exit;
}
}



function  Inc($f)
{
ob_start();
@include($f);
$content = ob_get_contents();
ob_end_clean();
if (substr($content, 0, 2) == '#!')
{
$content = substr($content, strpos($content, \n)+1);
}
return $content;
}
/test.php

testinc.php
#!/usr/bin/php
?php
echo testinc\n;
/testinc.php

output
[EMAIL PROTECTED]:~$ ./test.php
arse
testinc
/output

-Stut





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: [SOLVEDish] Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Jochem Maas

Nathan Rixham schreef:

how's this?

#!/usr/bin/php
?php
class trimshebang {
  function filter($in, $out, $consumed, $closing)
  {
while ($bucket = stream_bucket_make_writeable($in)) {
  $bucket-data = ltrim($bucket-data,#!/usr/bin/php\n);
  $consumed += $bucket-datalen;
  stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
  }
}

stream_filter_register(trim.shebang, trimshebang);
include php://filter/read=trim.shebang/resource=/path/to/include.php;
?

bit more graceful ;)


it's sick, I like it, nice example of streams filtering while your at it.
I learned something! it also works in so far that the shebang line is no longer
output but the output buffering in *my* script(s) doesn't work, whilst the same
construction does work in Stut's test scripts (although whilst playing with
his script I did manage to bork ik so that the output buffering *doesn't* work
there anymore ... how I did that I can't fathom)

anyway - they problem has been nicely shoved under the carpet. apart from
the shebang lines the script don't ever output anything anyway but rather
log to files ... a simple redirect output to /dev/null in the command line
that is used to run the 'master' script will take care of any spurious cruft
ending up on screen.

thanks to everyone for their input regarding my output! :-)





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Casey
On Thu, Feb 28, 2008 at 3:39 AM, Jochem Maas [EMAIL PROTECTED] wrote:
 hi there,

  I can't seem to manage to buffer output (of an included file) in a CLI 
 script,
  the following does not work:


  // buffer output so we can avoid the shebang line being 
 output (and strip it from the output we log)
  $oldIFvalue = ini_set('implicit_flush', false);
  ob_start();

  if ([EMAIL PROTECTED] $script) {
  ob_end_clean();
  } else {
  $output = explode(\n, ob_get_clean());
  if ($output[0]  preg_match('%^#!\/%', $output[0]))
  unset($output[0]);
  }

  ini_set('implicit_flush', $oldIFvalue);


  the reason I'm wanting to do this is, primarily, in order to stop the 
 shebang line that *may*
  be present in the included script from being output to stdout.


I use Windows, so I don't need the shebang line. But if I'm correct
and the shebang line is:

#!/usr/bin/php

, shouldn't it be considered a comment, because of the #?

-- 
-Casey

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering in CLI script.

2008-02-28 Thread Jim Lucas

Casey wrote:

On Thu, Feb 28, 2008 at 3:39 AM, Jochem Maas [EMAIL PROTECTED] wrote:

hi there,

 I can't seem to manage to buffer output (of an included file) in a CLI script,
 the following does not work:


 // buffer output so we can avoid the shebang line being 
output (and strip it from the output we log)
 $oldIFvalue = ini_set('implicit_flush', false);
 ob_start();

 if ([EMAIL PROTECTED] $script) {
 ob_end_clean();
 } else {
 $output = explode(\n, ob_get_clean());
 if ($output[0]  preg_match('%^#!\/%', $output[0]))
 unset($output[0]);
 }

 ini_set('implicit_flush', $oldIFvalue);


 the reason I'm wanting to do this is, primarily, in order to stop the shebang 
line that *may*
 be present in the included script from being output to stdout.



I use Windows, so I don't need the shebang line. But if I'm correct
and the shebang line is:

#!/usr/bin/php

, shouldn't it be considered a comment, because of the #?



nope, because it comes before the ?php in the file

If it were after the ?php then it would be considered a comment.

Jim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Output Buffering and zlib Compression Issue

2007-08-03 Thread Jan Reiter
Hi! 

I'm not quite sure what you are trying to do ... 
Why do you use output buffering in your code, when you turn it off in the
htaccess directive??
php_flag output_buffering Off

The code worked for me. But I tested it without your htaccess settings ... 

Jan

-Ursprüngliche Nachricht-
Von: Chris [mailto:[EMAIL PROTECTED] 
Gesendet: Samstag, 4. August 2007 01:18
An: php-general@lists.php.net
Betreff: [PHP] Output Buffering and zlib Compression Issue

When I run the following code (PHP 5.2.2, 5.2.3) via Apache (with an  
htaccess file), I get this error:

Notice: ob_end_clean() [ref.outcontrol]: failed to delete buffer zlib  
output compression. in ...

Can anyone explain what's going on?

I'm assuming it isn't a bug and I've read the documentation. Did I  
miss something?


htaccess file code:

php_flag output_buffering Off
php_flag zlib.output_compression On
php_value zlib.output_compression_level -1


PHP Code:

?php

error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');

ob_start();

echo You shouldn't see this.;

while (ob_get_level()  0) {
 ob_end_clean();
}

ob_start();

echo You SHOULD see this.;

ob_end_flush();

?

Chris




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Output Buffering and zlib Compression Issue

2007-08-03 Thread Jan Reiter
Right! 

With zlib compression ob_start() or similar seems to get called before the
user 
script execution. I'm not quite sure why. Anyhow ob_get_level() returns 2
after 
the ob_start() is called for the first time in the script. You can avoid the
error 
with

while (ob_get_level()  1) {
ob_end_clean();
}

but it won't kill the buffer containing output before ob_start() is called. 

ob_end_clean();
ob_end_clean();

will reproduce your error, too. This leads to the assumption, that it is an
issue
of advancing the functions internal process pointer.

Same reason why 

$data1 = mysql_fetch_assoc($resultid);
$data2 = mysql_fetch_assoc($resultid);

won't lead to the desired effect either, but 

While($data = mysql_fetch_assoc($resultid)){...}

does, as does

while (@ob_end_clean());

It seems only this way of accessing the buffers allows deleting the
lowermost buffer created before
Script execution.

Jan


-Original Message-
From: Chris [mailto:[EMAIL PROTECTED] 
Sent: Saturday, August 04, 2007 3:25 AM
To: php-general@lists.php.net
Subject: [PHP] Re: Output Buffering and zlib Compression Issue

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering / output compression

2005-06-11 Thread Richard Lynch
On Thu, June 9, 2005 12:22 am, Paul Birnstihl said:
 I have recently set up a machine with PHP with both buffering and
 compression turned on. Some of the pages being served include up to 3MB
 of HTML.

 Can someone explain the benefit(s) of setting these ini directives to
 values (ie. larger than 4kb) rather than On ?

 I've played around with it as I thought it might speed things up by
 using a bigger buffer etc. but the only difference I noticed is a big
 jump in memory usage.

If you somehow manage to spew out more than 3MB before you try to call
header() or session_start() or whatever, then the buffer got dumped, and
it's too late.

At least, that's how I think it would work...

But I never turn buffering on anyway, so what do I know?

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Output buffering - saving + echoing

2004-12-15 Thread Brent Baisley
Not exactly sure what your question is. You want to catch the buffer, 
but don't delay the buffer to be sent???
If your question is that you want to hold the contents of the buffer 
and send it only when you are ready, don't use ob_end_flush, use 
ob_end_clean. The buffer is cleared without sending anything to the 
client. The buffer contents are still retained in the variable $buf. 
When you are ready, you can just echo $buf.

The biggest advantage to output buffering, from a client server view, 
is that the contents can be compressed before sending to the client if 
the client supports compression (most browsers do). You'll get the best 
performance when you send everything at once instead of piecemeal.

On Dec 14, 2004, at 9:01 PM, Lorderon wrote:
Hi,
When using ob_start(), the output is buffered and not sent till
ob_end_flush() is called or got to end of the script. Also before 
flushing
you can get the buffer contents by ob_get_contents().

?
//start buffering, from now on no output.
//NEED: start buffering, but output imediatly when echo.
ob_start();
//this is not echoed now.
//NEED: echo this now, but still buffer it too.
echo Hello, World!;
//getting the buffer contents.
//NEED: getting the buffer contents.
$buf=ob_get_contents();
//the buffer is echoed just now.
//NEED: stop the buffering, and not output all the buffer now.
ob_end_flush();
?
What I want to do is catch the output buffer, but do not delay the 
buffer
to be sent. How is it done?

thanks in advance,
Lorderon.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search  Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Output buffering - saving + echoing

2004-12-15 Thread Lorderon
Hi,

Brent Baisley [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Not exactly sure what your question is. You want to catch the buffer,
 but don't delay the buffer to be sent???
 If your question is that you want to hold the contents of the buffer
 and send it only when you are ready, don't use ob_end_flush, use
 ob_end_clean. The buffer is cleared without sending anything to the
 client. The buffer contents are still retained in the variable $buf.
 When you are ready, you can just echo $buf.

Thanks, but this is now what i meant for.
I want the script to output data as regular like not using buffering. But I
want to catch output chunks in variables. How this can be done?

thanks,
Lorderon.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Output buffering - saving + echoing

2004-12-15 Thread Lorderon
Hi,

Brent Baisley [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Not exactly sure what your question is. You want to catch the buffer,
 but don't delay the buffer to be sent???
 If your question is that you want to hold the contents of the buffer
 and send it only when you are ready, don't use ob_end_flush, use
 ob_end_clean. The buffer is cleared without sending anything to the
 client. The buffer contents are still retained in the variable $buf.
 When you are ready, you can just echo $buf.

Thanks, but this is now what i meant for.
I want the script to output data as regular like not using buffering. But I
want to catch output chunks in variables. How this can be done?

thanks,
Lorderon.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Output buffering - saving + echoing

2004-12-15 Thread Richard Lynch
Lorderon wrote:
 What I want to do is catch the output buffer, but do not delay the
 buffer
 to be sent. How is it done?

I see three options here:

#1 Call ob_start/ob_get_contents/ob_flush and repeat that a *LOT* within
your script, so that you are buffering only a few lines of text at any
given time:
?php
  $BUFFER = '';
  ob_start();
  echo Foo!BR\n;
  $BUFFER .= ob_get_contents();
  ob_end_flush();

  ob_start();
  echo Bar!BR\n;
  $BUFFER .= ob_get_contents();
  ob_end_flush();
?

#2
function buffer_print($text){
  global $BUFFER;
  $BUFFER .= $text;
  print($text);
}

You could make #2 more fancy by accepting multiple arguments and using
echo instead of print internally.

#3
Write an extra script that does like this:
?php
  $file = file($real_url_they_asked_for);
  $BUFFER = implode('', $file);
  echo $file;
?

#3 is going to be horrible for large pages, however.


It occurs to me that maybe you should tell us WHY you want this, because
there could be existing alternatives outside the scope of PHP that we
could recommend...

Caching servers such as Squid or Accelerators such as Zend Optimizer
spring to mind.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering display handlers....

2004-03-16 Thread Tom Rogers
Hi,

Wednesday, March 17, 2004, 11:36:02 AM, you wrote:
P Hi Folks,

P I am trying to use outbuffering techniques

P ob_start(myCallBack)
P .
P ob_end_flush()

P function myCallBack($inBuffer)
P {
P //process
P ob_start();
P include aPHPFile.php;
P $includeFileContents = ob_get_contents();
P ob_end_clean();
P }

P I am seeing the following error Cannot use output buffering in output
P buffering display handlers ...is there an workaround of including this file
P using the php engine or alternative solution of getting access to php
P internal outbuffer inside an output handler callback...

P Thanks


you could try something like this

ob_start(myCallBack)
.
.
ob_start();
include aPHPFile.php;
$footer = ob_end_flush();
ob_end_flush()

function myCallBack($inBuffer)
{
//process
return $inbuffer.$GLOBALS['footer'];
}


Depends what you are trying to achieve over a simple include at the
end???
-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] output buffering

2003-02-27 Thread Leif K-Brooks
You can't display an image like that in HTML.  You need to make a second
PHP script that displays just the image, and call it with a img tag.
Kevin Waterson wrote:

I am having some problems with ob_*

My goals is basically this

htmlStuff goes here
?php header('Content-Type: image/jpeg'); echo 
file_get_contents('img.jpg';?
More stuff here/html

The code below works until the showImage method is called, it does 
show the image
however, it does not output the 'Stuff goes here!' line.

any guidance greatfully recieved.
Code is below..

Kevin


?php
class thumbs {

function thumbs(){

}


function showThumbs(){
return 'Thumbs';
}


function select(){
if(isset($_GET['show']))
{
return $this-showImage($_GET['show']);
}
  else
{
return $buffer.$this-showThumbs();
}
}


function showImage(){
  $size = getimagesize ('./australia.jpg');
  if ($size)
{
header(Content-type: {$size['mime']});
return file_get_contents('australia.jpg');
}
  else
{
return ' was not found on this server';
}
}
}  // end class

$thumbs = new thumbs;

ob_start(array($thumbs,'select'));

?
html
Stuff goes here!
?php
ob_end_flush();
?

/html





--
The above message is encrypted with double rot13 encoding.  Any 
unauthorized attempt to decrypt it will be prosecuted to the full extent 
of the law.





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] output buffering problem

2002-11-16 Thread Colin Kettenacker
webmaster [EMAIL PROTECTED] on 11/15/02 3:47 PM wrote:

 I'm trying to enable output buffering to speed up the load time of some
 of our php web pages.  I've consulted the manual and enabled the
 following:

The manual lacks description for this topic. Take a look at this article at
Developer Shed, it got me up and running within 10 minutes.

http://www.devshed.com/Server_Side/PHP/OutputBuffering/page1.html

HTH,

ck



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Output Buffering - Am I using it correctly?

2002-09-25 Thread Kevin Stone

Output buffering is doing nothing for you in the given example.  It does not
reduce client side resources... if anything it increases the usage
serverside resources.  Perhaps you are thinking of gz compression?  You
might use a combination of ob* functions and gz* functions to minimize
bandwidth requirments.. but there's no guarantee that your user's browsers
supports it.

http://www.php.net/manual/en/printwn/function.gzcompress.php

-Kevin

- Original Message -
From: Jay Blanchard [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, September 25, 2002 10:45 AM
Subject: [PHP] Output Buffering - Am I using it correctly?


 Howdy group!

 I am outputting a rather large data set to an Excel spreadsheet from a
MySQL
 database on a healthy FreeBSD server. The Apache server is on the same
 server as the database. The code looks like this

 ?
 /*
 ** SWB CABS Project
 ** USOC Charges Detail
 ** Report By Criteria - Spreadsheet
 */

 // open output buffer
 ob_start();

 // excel headers
 header(Content-Type:  application/vnd.ms-excel);
 header(Content-Disposition: inline; filename=\excel.xls\);
 header(Expires: 0);
 header(Cache-Control: must-revalidate, post-check=0, pre-check=0);

 
 /*
 ** lots of code that gets roughly
 ** 15,000 - 20,000 rows of data
 ** each row is 209 bytes of data
 */
 

 // close output buffer
 ob_end_flush();
 ?

 Now, even though I have set ob_start() the headers get sent (as it says in
 the docs; While output buffering is active no output is sent from the
 script (other than headers), instead the output is stored in an internal
 buffer. )

 The Task Manager shows that the processes on my local machine for
EXCEL.EXE
 go to the maximum available CPU cycles and stays there until the
spreadsheet
 is either delivered or the system times out. I thought that using output
 buffering would lower use of client system resources. Is this not true?

 Thanks!

 Jay



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Output Buffering - Am I using it correctly?

2002-09-25 Thread Jay Blanchard

[snip]
Output buffering is doing nothing for you in the given example.  It does not
reduce client side resources... if anything it increases the usage
serverside resources.  Perhaps you are thinking of gz compression?  You
might use a combination of ob* functions and gz* functions to minimize
bandwidth requirments.. but there's no guarantee that your user's browsers
supports it.
[/snip]

Fatal error: Call to undefined function: gzcompress() in
/var/lib/apache/htdocs/swbcabs/gen.php on line 89

I guess that this means I am out of luck here. Anyone know a cleaner method
for delivering spreadsheets?

Thanks!

Jay



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Output Buffering - Am I using it correctly?

2002-09-25 Thread Beau Hartshorne

 I guess that this means I am out of luck here. Anyone know a cleaner 
 method for delivering spreadsheets?

Can you get the server to write it to a file, and then let the client
download the file normally?

Beau



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Output Buffering - Am I using it correctly?

2002-09-25 Thread Jay Blanchard

[snip]
 I guess that this means I am out of luck here. Anyone know a cleaner
 method for delivering spreadsheets?

Can you get the server to write it to a file, and then let the client
download the file normally?
[/snip]

Believe me, if I could have taken that way out I would have done it. I am
researching some classes, but they all seem to take just as long to create
the spreadsheet.

Jay



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Output Buffering - Am I using it correctly?

2002-09-25 Thread Jay Blanchard

[snip]
 I am researching some classes 
[/snip]

OK. One of the silly classes fails, saying --

Fatal error: No parent class available in this context in biff.php on line
52

line 52 is --

49 function BiffWriter()
50  {
51  error_reporting (E_ALL);
52  parent::BiffBase();
53  $this-_fill_AA_notation();
54  }

This is on a server with PHP 4.04. Does anyone have any clues as to why it
might not work?
ACCCK! I am so frustrated at this point that I would almost rather write
spreadsheets by hand!

Thanks for your help!

Jay



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Output Buffering - Am I using it correctly?

2002-09-25 Thread Beau Hartshorne

 Can you get the server to write it to a file, and then let the client
 download the file normally?
 [/snip]
 
 Believe me, if I could have taken that way out I would have done it. I
am
 researching some classes, but they all seem to take just as long to
create
 the spreadsheet.

What about something like this:

1. Script loads. Script writes everything to some file.
2. Script is finished writing everything to file.
4. Script does a browser redirect and the user starts downloading the
file normally.

It just seems like the server doesn't want to have to deal with
streaming a large database result set to a web browser.

Beau



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Output Buffering - Am I using it correctly?

2002-09-25 Thread Jay Blanchard

[snip]
OK. One of the silly classes fails, saying --

Fatal error: No parent class available in this context in biff.php on line
52

line 52 is --

49 function BiffWriter()
50  {
51  error_reporting (E_ALL);
52  parent::BiffBase();
53  $this-_fill_AA_notation();
54  }

This is on a server with PHP 4.04. Does anyone have any clues as to why it
might not work?
[/snip]

I actually identified this in the above post without realizing it. The 4.04
version of PHP does not support the parent:: directive. Ah well, looks like
we're going to have to clear some time for an upgrade.

Thanks!

Jay



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] output buffering

2001-04-05 Thread Christian Dechery

At 00:26 5/4/2001 -0500, Plutarck wrote:
http://www.php.net/manual/en/ref.outcontrol.php

If you want to use output buffering you must use the ob_* family of
functions.

In any script where you want it used you _must_ use it explicitly, or so do
in an included file. Unless you can change the php.ini, there is no way to
force all pages to use output buffering. I don't reccommend you do such a
thing anyway.

If you aren't using output compression all it does is allow bad programming
practices. One exception is for hosting companies that want to force ads to
be displayed on the page with the auto_prepend type settings.


Output buffering should only be used if you have a specific reason for doing
so. Kind of like all PHP functions :)

It doesn't cost much in performance except when a script pumps out a very
large amount of data. If you want to print a 10mb text file to the browser
it is a considerably _BAD_ idea to force PHP to buffer that all up into one
chunk before puking it out.


But, enter the gz_handler functions. If you want to compress your output,
then you have a reason for using output buffering. The cost in performance
varies widely, but if your server is already under a considerable load you
probably shouldn't use it.

But it's very cool to use if you have the extra processor power, but wait
for 4.0.5 to do it. Many people complain about memory leaks and sub-standard
output buffering functions. It's supposed to all be fixed in the new
version, so feel free to play around with it :)

Still, it's better to be able to set it only in the places you want it run
rather than making all output use it.

exactly... I don't want to set this option to an entire site just because 
of one little script I'm having trouble setting a header() or 
setcookie()... and I wanna use them in the middle of the output...
something like ASP's % response.flush=true %, it can be set anywhere u 
want...
but of course... the best way is to code right and not to mess with headers 
once the output has started... but sometimes I wish I could, u know? It 
would really make somethings a lot simpler...

. Christian Dechery (lemming)
. http://www.tanamesa.com.br
. Gaita-L Owner / Web Developer


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] output buffering

2001-04-05 Thread Plutarck

I know what you mean. Until I decided to kill all but one single echo/print
call, which is in a function I call at the bottom of the script, I often ran
into problems where I needed to echo something at the top of a really really
long control loop, but nested deep within it I had to set a cookie or use a
redirect.

Which is why I killed all my echo/print calls in favor of a single function
which I include at the bottom of my script ;)


--
Plutarck
Should be working on something...
...but forgot what it was.


"Christian Dechery" [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 At 00:26 5/4/2001 -0500, Plutarck wrote:
 http://www.php.net/manual/en/ref.outcontrol.php
 
 If you want to use output buffering you must use the ob_* family of
 functions.
 
 In any script where you want it used you _must_ use it explicitly, or so
do
 in an included file. Unless you can change the php.ini, there is no way
to
 force all pages to use output buffering. I don't reccommend you do such a
 thing anyway.
 
 If you aren't using output compression all it does is allow bad
programming
 practices. One exception is for hosting companies that want to force ads
to
 be displayed on the page with the auto_prepend type settings.
 
 
 Output buffering should only be used if you have a specific reason for
doing
 so. Kind of like all PHP functions :)
 
 It doesn't cost much in performance except when a script pumps out a very
 large amount of data. If you want to print a 10mb text file to the
browser
 it is a considerably _BAD_ idea to force PHP to buffer that all up into
one
 chunk before puking it out.
 
 
 But, enter the gz_handler functions. If you want to compress your output,
 then you have a reason for using output buffering. The cost in
performance
 varies widely, but if your server is already under a considerable load
you
 probably shouldn't use it.
 
 But it's very cool to use if you have the extra processor power, but wait
 for 4.0.5 to do it. Many people complain about memory leaks and
sub-standard
 output buffering functions. It's supposed to all be fixed in the new
 version, so feel free to play around with it :)
 
 Still, it's better to be able to set it only in the places you want it
run
 rather than making all output use it.

 exactly... I don't want to set this option to an entire site just because
 of one little script I'm having trouble setting a header() or
 setcookie()... and I wanna use them in the middle of the output...
 something like ASP's % response.flush=true %, it can be set anywhere u
 want...
 but of course... the best way is to code right and not to mess with
headers
 once the output has started... but sometimes I wish I could, u know? It
 would really make somethings a lot simpler...
 
 . Christian Dechery (lemming)
 . http://www.tanamesa.com.br
 . Gaita-L Owner / Web Developer


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] output buffering

2001-04-04 Thread Plutarck

http://www.php.net/manual/en/ref.outcontrol.php

If you want to use output buffering you must use the ob_* family of
functions.

In any script where you want it used you _must_ use it explicitly, or so do
in an included file. Unless you can change the php.ini, there is no way to
force all pages to use output buffering. I don't reccommend you do such a
thing anyway.

If you aren't using output compression all it does is allow bad programming
practices. One exception is for hosting companies that want to force ads to
be displayed on the page with the auto_prepend type settings.


Output buffering should only be used if you have a specific reason for doing
so. Kind of like all PHP functions :)

It doesn't cost much in performance except when a script pumps out a very
large amount of data. If you want to print a 10mb text file to the browser
it is a considerably _BAD_ idea to force PHP to buffer that all up into one
chunk before puking it out.


But, enter the gz_handler functions. If you want to compress your output,
then you have a reason for using output buffering. The cost in performance
varies widely, but if your server is already under a considerable load you
probably shouldn't use it.

But it's very cool to use if you have the extra processor power, but wait
for 4.0.5 to do it. Many people complain about memory leaks and sub-standard
output buffering functions. It's supposed to all be fixed in the new
version, so feel free to play around with it :)

Still, it's better to be able to set it only in the places you want it run
rather than making all output use it.


--
Plutarck
Should be working on something...
...but forgot what it was.


"Christian Dechery" [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 as I saw on the manual output_buffering cannot be changed at runtime... so
 there is NO WAY? If I want output_buffering I'll have to do it on all my
pages?

 and does it really cost that much in performance? is it worthed?
 
 . Christian Dechery (lemming)
 . http://www.tanamesa.com.br
 . Gaita-L Owner / Web Developer


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]