You are here: Re: Why does it wait before echoing? « All PHP « IT news, forums, messages
Re: Why does it wait before echoing?

Posted by Rik on 08/04/07 21:43

On Sat, 04 Aug 2007 23:18:00 +0200, Matthew White <mgw854@msn.com> wrote:

> "Rik" <luiheidsgoeroe@hotmail.com> wrote in message
> news:op.twjxk0d2qnv3q9@metallium...
>> On Sat, 04 Aug 2007 21:57:04 +0200, Mad Hatter <colin@class31.co.uk>
>> wrote:
>>
>>> Hi
>>>
>>> I've written a little routine for backing up a large(ish) mysql
>>> database.
>>> Basically what I want it to do is echo to the screen 'backing up table
>>> 1',
>>> 'backing up table 2' etc as it's going along. The routine runs along
>>> the
>>> following lines
>>>
>>> while ($i < $tables) {
>>> echo "Backing up table $i";
>>>
>>> opens a file here
>>> it reads the table from the database here
>>> writes it to a file here
>>> closes file
>>>
>>> }
>>>
>>> I expected after each read/write it would output "Backing up table x"
>>> but
>>> it reads/writes them all and then echoes all the backing up text in
>>> one go.
>>> What am I doing wrong?
>>
>> There's a caching/buffer mechanism somewhere. Try to use flush() after
>> each echo, maybe it helps, maybe it doesn't: it can depend on server &
>> browser. See the description & user contributed notes in the manual for
>> flush().

> No, the problem is your language. PHP creates HTML pages. It doesn't
> modify them on-the-fly.

Nonsense, PHP _can_ create HTML pages. It can do many things. Hell, I
wouldn't recommend it to anyone, but writing a full (locally running)
windows application is not out of the question..

> A page that says:

Page, page? A script somewhere you mean?

> <?php
> while ($i < $tables) {
> echo "Backing up table $i";
> ?>
> will output an HTML file:

What file are you talking about? It doesn't exist as a file, nowhere,
unless maybe in the browser cache.

> <body>

Euhm, no, I'm not aware of a, HTML body tag magically appearing anywhere
as output of my scripts unless I explicitly tell it to do so.

> Backing up table 1Backing up table 2

Yes, which is what he wants, seeping in progress reports as the process
goes. Perfectly suited for your own backup script to check, not to use as
a general user interface, I'll give you that. Then again, where exactly
did the OP say he used a browser/HTML for this? It could very well be the
command line, allthough it's less likely a buffering mechanism is active
there, that's why I assumed it was the case.

> </body>
>
> This HTML file

Is none existent. There is no file.

> is then downloaded by the browser.

This html is received by the browser is a mote appropriate term if there
is no file. And current browsers can handle 'slow' pages quite good. And
by no means does PHP need to finish 'writing a file' before it can be
'downloaded' in normal PHP use.

If you want to bitch about something, it should be that this can take so
much time the browser times out, and doesn't display progress anymore.
With the right configuration, PHP doesn't matter it is sending its
progress report in the course of several hours. And _if_ it is HTML which
it is outputting (which might as well be an image, bytecode, or any other
random stream of bits), it can be configured not to care about any HTML
connection whatsoever.

> If you want interactivity, try using JavaScript instead.

Where did he stated that he wanted 'interactivity'?

In short: read up, and ask nicely 'but I thought this was how it worked,
am I wrong?' if you don't understand something, instead of stating
bullshit.
--
Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация