Welcome! Log In Create A New Profile

Advanced

[PHP] Output text status on a long class

Posted by Chrome 
Chrome
[PHP] Output text status on a long class
October 14, 2008 05:00PM
Hi all

I have a class that takes a while to run and am wanting to push some output
to the browser while it's doing its stuff. Is that possible?

Here's what I'd like:

Connecting to server... Done!
Retrieving categories... Done!
....

All I can get it to do is output all of the text at the end of the script

A voice in my head says that outputting all of the text at the end of the
script is the only way to do it. Then another voice says but there must be
a way! :)

I did try a quick test of buffering the text then explicitly flushing the
buffer but it didn't seem to work

I know this seems pointless but I'm anticipating that the users will be
confused (which would be a surprise </sarcasm>) and attempt to abort/bugger
off somewhere else

Thanks in advance!

Dan


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Stut
Re: [PHP] Output text status on a long class
October 14, 2008 05:10PM
On 14 Oct 2008, at 15:56, Chrome wrote:
> I have a class that takes a while to run and am wanting to push some
> output
> to the browser while it's doing its stuff. Is that possible?
>
> Here's what I'd like:
>
> Connecting to server... Done!
> Retrieving categories... Done!
> ...
>
> All I can get it to do is output all of the text at the end of the
> script
>
> A voice in my head says that outputting all of the text at the end
> of the
> script is the only way to do it. Then another voice says but there
> must be
> a way! :)
>
> I did try a quick test of buffering the text then explicitly
> flushing the
> buffer but it didn't seem to work
>
> I know this seems pointless but I'm anticipating that the users will
> be
> confused (which would be a surprise </sarcasm>) and attempt to abort/
> bugger
> off somewhere else

Put this line at the top of your script...

while (@ob_end_clean());

That will remove any output buffers and your script should then output
stuff as it happens.

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
uaca man
Re: [PHP] Output text status on a long class
October 14, 2008 05:15PM
Dan,

Try
echo "some text";
ob_flush() http://br2.php.net/manual/en/function.ob-flush.php;
*flush()* ;

also take a look at the documentation at:
http://br2.php.net/manual/en/function.flush.php

Angelo

2008/10/14 Chrome <[email protected]>

> Hi all
>
> I have a class that takes a while to run and am wanting to push some output
> to the browser while it's doing its stuff. Is that possible?
>
> Here's what I'd like:
>
> Connecting to server... Done!
> Retrieving categories... Done!
> ...
>
> All I can get it to do is output all of the text at the end of the script
>
> A voice in my head says that outputting all of the text at the end of the
> script is the only way to do it. Then another voice says but there must be
> a way! :)
>
> I did try a quick test of buffering the text then explicitly flushing the
> buffer but it didn't seem to work
>
> I know this seems pointless but I'm anticipating that the users will be
> confused (which would be a surprise </sarcasm>) and attempt to abort/bugger
> off somewhere else
>
> Thanks in advance!
>
> Dan
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Chrome
RE: [PHP] Output text status on a long class
October 14, 2008 05:20PM
> -----Original Message-----
> From: uaca man [mailto:[email protected]]
> Sent: 14 October 2008 16:10
> To: php-general@lists.php.net
> Subject: Re: [PHP] Output text status on a long class
>
> Dan,
>
> Try
> echo "some text";
> ob_flush() http://br2.php.net/manual/en/function.ob-flush.php;
> *flush()* ;
>
> also take a look at the documentation at:
> http://br2.php.net/manual/en/function.flush.php
>
> Angelo
>

Hi Angelo and Stut

Strange happenings. Tried a few combinations of your suggestions but the
output is still just dumped at the end

Odd

Thanks for the input (and this may be something to do with the server (which
I didn't set up))

Dan



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jay Moore
Re: [PHP] Output text status on a long class
October 14, 2008 05:25PM
Stut wrote:
> On 14 Oct 2008, at 15:56, Chrome wrote:
>> I have a class that takes a while to run and am wanting to push some
>> output
>> to the browser while it's doing its stuff. Is that possible?
>>
>> Here's what I'd like:
>>
>> Connecting to server... Done!
>> Retrieving categories... Done!
>> ...
>>
>> All I can get it to do is output all of the text at the end of the script
>>
>> A voice in my head says that outputting all of the text at the end of the
>> script is the only way to do it. Then another voice says but there
>> must be
>> a way! :)
>>
>> I did try a quick test of buffering the text then explicitly flushing the
>> buffer but it didn't seem to work
>>
>> I know this seems pointless but I'm anticipating that the users will be
>> confused (which would be a surprise </sarcasm>) and attempt to
>> abort/bugger
>> off somewhere else
>
> Put this line at the top of your script...
>
> while (@ob_end_clean());
>
> That will remove any output buffers and your script should then output
> stuff as it happens.
>
> -Stut
>

Or you could add

flush();

after your output, which will flush the output buffer and force it to
display.

Jay

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Andrew Ballard
Re: [PHP] Output text status on a long class
October 14, 2008 05:30PM
On Tue, Oct 14, 2008 at 11:19 AM, Chrome <[email protected]> wrote:
>
>
>> -----Original Message-----
>> From: uaca man [mailto:[email protected]]
>> Sent: 14 October 2008 16:10
>> To: php-general@lists.php.net
>> Subject: Re: [PHP] Output text status on a long class
>>
>> Dan,
>>
>> Try
>> echo "some text";
>> ob_flush() http://br2.php.net/manual/en/function.ob-flush.php;
>> *flush()* ;
>>
>> also take a look at the documentation at:
>> http://br2.php.net/manual/en/function.flush.php
>>
>> Angelo
>>
>
> Hi Angelo and Stut
>
> Strange happenings. Tried a few combinations of your suggestions but the
> output is still just dumped at the end
>
> Odd
>
> Thanks for the input (and this may be something to do with the server (which
> I didn't set up))
>
> Dan

There could be other causes, including the browser. Read the author's
note on this page:

http://www.hudzilla.org/phpbook/read.php/13_9_0

I'm not sure what browsers might have similar limits. I suspect they
do it because they usually download full documents all at once rather
than in delayed increments and they want to eliminate a lot of
unnecessary page reflows as content is being delivered. I think I've
even seen a FF extension that waits to display anything until the full
page has been downloaded since it makes pages appear to download
faster.

Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Chrome
RE: [PHP] Output text status on a long class
October 14, 2008 05:35PM
> Stut wrote:
> > On 14 Oct 2008, at 15:56, Chrome wrote:
> >> I have a class that takes a while to run and am wanting to push some
> >> output
> >> to the browser while it's doing its stuff. Is that possible?
> >>
> >> Here's what I'd like:
> >>
> >> Connecting to server... Done!
> >> Retrieving categories... Done!
> >> ...
> >>
> >> All I can get it to do is output all of the text at the end of the
> script
> >>
> >> A voice in my head says that outputting all of the text at the end
> of the
> >> script is the only way to do it. Then another voice says but there
> >> must be
> >> a way! :)
> >>
> >> I did try a quick test of buffering the text then explicitly
> flushing the
> >> buffer but it didn't seem to work
> >>
> >> I know this seems pointless but I'm anticipating that the users will
> be
> >> confused (which would be a surprise </sarcasm>) and attempt to
> >> abort/bugger
> >> off somewhere else
> >
> > Put this line at the top of your script...
> >
> > while (@ob_end_clean());
> >
> > That will remove any output buffers and your script should then
> output
> > stuff as it happens.
> >
> > -Stut
> >
>
> Or you could add
>
> flush();
>
> after your output, which will flush the output buffer and force it to
> display.

I did that as well as stut's suggestion. And I tried ob_flush() (just in
case). Tried a few combinations

Personally I think I sometimes have a negative effect on these things

Dan

> 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
Andrew Ballard
Re: [PHP] Output text status on a long class
October 14, 2008 05:40PM
On Tue, Oct 14, 2008 at 11:30 AM, Chrome <[email protected]> wrote:
>> Stut wrote:
>> > On 14 Oct 2008, at 15:56, Chrome wrote:
>> >> I have a class that takes a while to run and am wanting to push some
>> >> output
>> >> to the browser while it's doing its stuff. Is that possible?
>> >>
>> >> Here's what I'd like:
>> >>
>> >> Connecting to server... Done!
>> >> Retrieving categories... Done!
>> >> ...
>> >>
>> >> All I can get it to do is output all of the text at the end of the
>> script
>> >>
>> >> A voice in my head says that outputting all of the text at the end
>> of the
>> >> script is the only way to do it. Then another voice says but there
>> >> must be
>> >> a way! :)
>> >>
>> >> I did try a quick test of buffering the text then explicitly
>> flushing the
>> >> buffer but it didn't seem to work
>> >>
>> >> I know this seems pointless but I'm anticipating that the users will
>> be
>> >> confused (which would be a surprise </sarcasm>) and attempt to
>> >> abort/bugger
>> >> off somewhere else
>> >
>> > Put this line at the top of your script...
>> >
>> > while (@ob_end_clean());
>> >
>> > That will remove any output buffers and your script should then
>> output
>> > stuff as it happens.
>> >
>> > -Stut
>> >
>>
>> Or you could add
>>
>> flush();
>>
>> after your output, which will flush the output buffer and force it to
>> display.
>
> I did that as well as stut's suggestion. And I tried ob_flush() (just in
> case). Tried a few combinations
>
> Personally I think I sometimes have a negative effect on these things
>
> Dan
>

Did you also read the notes in the description for flush()?

http://www.php.net/manual/en/function.flush.php


Andrew

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Chrome
RE: [PHP] Output text status on a long class
October 14, 2008 05:55PM
> On Tue, Oct 14, 2008 at 11:30 AM, Chrome <[email protected]> wrote:
> >> Stut wrote:
> >> > On 14 Oct 2008, at 15:56, Chrome wrote:
> >> >> I have a class that takes a while to run and am wanting to push
> some
> >> >> output
> >> >> to the browser while it's doing its stuff. Is that possible?
> >> >>
> >> >> Here's what I'd like:
> >> >>
> >> >> Connecting to server... Done!
> >> >> Retrieving categories... Done!
> >> >> ...
> >> >>
> >> >> All I can get it to do is output all of the text at the end of
> the
> >> script
> >> >>
> >> >> A voice in my head says that outputting all of the text at the
> end
> >> of the
> >> >> script is the only way to do it. Then another voice says but
> there
> >> >> must be
> >> >> a way! :)
> >> >>
> >> >> I did try a quick test of buffering the text then explicitly
> >> flushing the
> >> >> buffer but it didn't seem to work
> >> >>
> >> >> I know this seems pointless but I'm anticipating that the users
> will
> >> be
> >> >> confused (which would be a surprise </sarcasm>) and attempt to
> >> >> abort/bugger
> >> >> off somewhere else
> >> >
> >> > Put this line at the top of your script...
> >> >
> >> > while (@ob_end_clean());
> >> >
> >> > That will remove any output buffers and your script should then
> >> output
> >> > stuff as it happens.
> >> >
> >> > -Stut
> >> >
> >>
> >> Or you could add
> >>
> >> flush();
> >>
> >> after your output, which will flush the output buffer and force it
> to
> >> display.
> >
> > I did that as well as stut's suggestion. And I tried ob_flush()
> (just in
> > case). Tried a few combinations
> >
> > Personally I think I sometimes have a negative effect on these things
> >
> > Dan
> >
>
> Did you also read the notes in the description for flush()?
>
> http://www.php.net/manual/en/function.flush.php

I'm reading through them now :)

For the record I have included a 256 char long whitespace string along with any prospective output but still no joy

Opera 9.60 reliably informs me it's received 258 bytes but displays nothing

I'll carry on with this for a little before blaming the browsers (testing also in FF3) and putting in a 'This is going to take bloody ages' note :)

Thanks for all the input

Dan

> Andrew
>
> --
> 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
Stut
Re: [PHP] Output text status on a long class
October 14, 2008 06:20PM
On 14 Oct 2008, at 16:51, Chrome wrote:
> For the record I have included a 256 char long whitespace string
> along with any prospective output but still no joy
>
> Opera 9.60 reliably informs me it's received 258 bytes but displays
> nothing
>
> I'll carry on with this for a little before blaming the browsers
> (testing also in FF3) and putting in a 'This is going to take bloody
> ages' note :)

My initial response was based on it being a CLI script in which case
my advice would have been enough. However in your case there are other
buffers in play which could affect the output.

How is your output formatted? Browsers won't necessarily display
content until they get closing tags. This is probably the issue you're
running into.

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Chrome
RE: [PHP] Output text status on a long class
October 14, 2008 06:40PM
> On 14 Oct 2008, at 16:51, Chrome wrote:
> > For the record I have included a 256 char long whitespace string
> > along with any prospective output but still no joy
> >
> > Opera 9.60 reliably informs me it's received 258 bytes but displays
> > nothing
> >
> > I'll carry on with this for a little before blaming the browsers
> > (testing also in FF3) and putting in a 'This is going to take bloody
> > ages' note :)
>
> My initial response was based on it being a CLI script in which case
> my advice would have been enough. However in your case there are other
> buffers in play which could affect the output.
>
> How is your output formatted? Browsers won't necessarily display
> content until they get closing tags. This is probably the issue you're
> running into.

The output is [currently] plain text only. Maybe it would help if I added
the standard HTML stuff too I'll have more luck

I'll try that in a little bit but food first :)

Thanks for the input

Dan

> -Stut
>
> --
> http://stut.net/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
Re: [PHP] Output text status on a long class
October 14, 2008 06:45PM
Chrome wrote:
>> On 14 Oct 2008, at 16:51, Chrome wrote:
>>> For the record I have included a 256 char long whitespace string
>>> along with any prospective output but still no joy
>>>
>>> Opera 9.60 reliably informs me it's received 258 bytes but displays
>>> nothing
>>>
>>> I'll carry on with this for a little before blaming the browsers
>>> (testing also in FF3) and putting in a 'This is going to take bloody
>>> ages' note :)
>> My initial response was based on it being a CLI script in which case
>> my advice would have been enough. However in your case there are other
>> buffers in play which could affect the output.
>>
>> How is your output formatted? Browsers won't necessarily display
>> content until they get closing tags. This is probably the issue you're
>> running into.
>
> The output is [currently] plain text only. Maybe it would help if I added
> the standard HTML stuff too I'll have more luck
>
> I'll try that in a little bit but food first :)
>
> Thanks for the input
>
> Dan
>
>> -Stut
>>
>> --
>> http://stut.net/
>
>

Also, a setting to check it to make sure that output_buffering, in the
PHP.ini, is set to off. I think the default is 4096bytes. You'll not want it
to do that. Once you change that, restart apache/iis/etc...


--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
Re: [PHP] Output text status on a long class
October 14, 2008 06:45PM
Chrome wrote:
>> On 14 Oct 2008, at 16:51, Chrome wrote:
>>> For the record I have included a 256 char long whitespace string
>>> along with any prospective output but still no joy
>>>
>>> Opera 9.60 reliably informs me it's received 258 bytes but displays
>>> nothing
>>>
>>> I'll carry on with this for a little before blaming the browsers
>>> (testing also in FF3) and putting in a 'This is going to take bloody
>>> ages' note :)
>> My initial response was based on it being a CLI script in which case
>> my advice would have been enough. However in your case there are other
>> buffers in play which could affect the output.
>>
>> How is your output formatted? Browsers won't necessarily display
>> content until they get closing tags. This is probably the issue you're
>> running into.
>
> The output is [currently] plain text only. Maybe it would help if I added
> the standard HTML stuff too I'll have more luck
>
> I'll try that in a little bit but food first :)
>
> Thanks for the input
>
> Dan
>
>> -Stut
>>
>> --
>> http://stut.net/
>
>


Also, a setting to check it to make sure that output_buffering, in the
PHP.ini, is set to off. I think the default is 4096bytes. You'll not want it
to do that. Once you change that, restart apache/iis/etc...

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Boyd, Todd M.
RE: [PHP] Output text status on a long class
October 14, 2008 06:50PM
> -----Original Message-----
> From: Jim Lucas [mailto:[email protected]]
> Sent: Tuesday, October 14, 2008 11:43 AM
> To: Chrome
> Cc: 'Stut'; 'Andrew Ballard'; 'Jay Moore'; php-general@lists.php.net
> Subject: Re: [PHP] Output text status on a long class
>
> Chrome wrote:
> >> On 14 Oct 2008, at 16:51, Chrome wrote:
> >>> For the record I have included a 256 char long whitespace string
> >>> along with any prospective output but still no joy
> >>>
> >>> Opera 9.60 reliably informs me it's received 258 bytes but
displays
> >>> nothing
> >>>
> >>> I'll carry on with this for a little before blaming the browsers
> >>> (testing also in FF3) and putting in a 'This is going to take
> bloody
> >>> ages' note :)
> >> My initial response was based on it being a CLI script in which
case
> >> my advice would have been enough. However in your case there are
> other
> >> buffers in play which could affect the output.
> >>
> >> How is your output formatted? Browsers won't necessarily display
> >> content until they get closing tags. This is probably the issue
> you're
> >> running into.
> >
> > The output is [currently] plain text only. Maybe it would help if I
> added
> > the standard HTML stuff too I'll have more luck
> >
> > I'll try that in a little bit but food first :)
> >
> > Thanks for the input
>
> Also, a setting to check it to make sure that output_buffering, in the
> PHP.ini, is set to off. I think the default is 4096bytes. You'll not
> want it
> to do that. Once you change that, restart apache/iis/etc...

OP wrote: "Thanks for the input (and this may be something to do with
the server (which I didn't set up))"

I'm thinking maybe they have no control over any INI settings that
cannot be changed programmatically on a per-script basis.


Todd Boyd
Web Programmer

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
Re: [PHP] Output text status on a long class
October 14, 2008 07:00PM
Boyd, Todd M. wrote:
>> -----Original Message-----
>> From: Jim Lucas [mailto:[email protected]]
>> Sent: Tuesday, October 14, 2008 11:43 AM
>> To: Chrome
>> Cc: 'Stut'; 'Andrew Ballard'; 'Jay Moore'; php-general@lists.php.net
>> Subject: Re: [PHP] Output text status on a long class
>>
>> Chrome wrote:
>>>> On 14 Oct 2008, at 16:51, Chrome wrote:
>>>>> For the record I have included a 256 char long whitespace string
>>>>> along with any prospective output but still no joy
>>>>>
>>>>> Opera 9.60 reliably informs me it's received 258 bytes but
> displays
>>>>> nothing
>>>>>
>>>>> I'll carry on with this for a little before blaming the browsers
>>>>> (testing also in FF3) and putting in a 'This is going to take
>> bloody
>>>>> ages' note :)
>>>> My initial response was based on it being a CLI script in which
> case
>>>> my advice would have been enough. However in your case there are
>> other
>>>> buffers in play which could affect the output.
>>>>
>>>> How is your output formatted? Browsers won't necessarily display
>>>> content until they get closing tags. This is probably the issue
>> you're
>>>> running into.
>>> The output is [currently] plain text only. Maybe it would help if I
>> added
>>> the standard HTML stuff too I'll have more luck
>>>
>>> I'll try that in a little bit but food first :)
>>>
>>> Thanks for the input
>> Also, a setting to check it to make sure that output_buffering, in the
>> PHP.ini, is set to off. I think the default is 4096bytes. You'll not
>> want it
>> to do that. Once you change that, restart apache/iis/etc...
>
> OP wrote: "Thanks for the input (and this may be something to do with
> the server (which I didn't set up))"
>
> I'm thinking maybe they have no control over any INI settings that
> cannot be changed programmatically on a per-script basis.
>
>
> Todd Boyd
> Web Programmer
>

This is a setting can be placed in a .htaccess file :)

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Boyd, Todd M.
RE: [PHP] Output text status on a long class
October 14, 2008 07:00PM
> -----Original Message-----
> From: Jim Lucas [mailto:[email protected]]
> Sent: Tuesday, October 14, 2008 11:56 AM
> To: Boyd, Todd M.
> Cc: php php
> Subject: Re: [PHP] Output text status on a long class
>
> Boyd, Todd M. wrote:
> >>
> >> Also, a setting to check it to make sure that output_buffering, in
> the
> >> PHP.ini, is set to off. I think the default is 4096bytes. You'll
> not
> >> want it
> >> to do that. Once you change that, restart apache/iis/etc...
> >
> > OP wrote: "Thanks for the input (and this may be something to do
with
> > the server (which I didn't set up))"
> >
> > I'm thinking maybe they have no control over any INI settings that
> > cannot be changed programmatically on a per-script basis.
>
> This is a setting can be placed in a .htaccess file :)

I was unaware. I know there are some that can and some that can't...
good to know that this one can. :)


Todd Boyd
Web Programmer

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
Re: [PHP] Output text status on a long class
October 14, 2008 07:05PM
Boyd, Todd M. wrote:
>> -----Original Message-----
>> From: Jim Lucas [mailto:[email protected]]
>> Sent: Tuesday, October 14, 2008 11:56 AM
>> To: Boyd, Todd M.
>> Cc: php php
>> Subject: Re: [PHP] Output text status on a long class
>>
>> Boyd, Todd M. wrote:
>>>> Also, a setting to check it to make sure that output_buffering, in
>> the
>>>> PHP.ini, is set to off. I think the default is 4096bytes. You'll
>> not
>>>> want it
>>>> to do that. Once you change that, restart apache/iis/etc...
>>> OP wrote: "Thanks for the input (and this may be something to do
> with
>>> the server (which I didn't set up))"
>>>
>>> I'm thinking maybe they have no control over any INI settings that
>>> cannot be changed programmatically on a per-script basis.
>> This is a setting can be placed in a .htaccess file :)
>
> I was unaware. I know there are some that can and some that can't...
> good to know that this one can. :)
>
>
> Todd Boyd
> Web Programmer
>

http://us.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login