> > > I dont think its possible without Java programing.

> > its posible to keep a http connection open and trust on flush() to send
some
> > data to the client, if this data contains javascript you could update a
> > window or something... if you want to make this safe: make sure you use
a
> > combination of a open http connection with flush() and reload the frame
your
> > flush()'ing time to time (in case of a proxy server)

> I've been kidding around with a chat experiment of my own a few weeks ago
and
> stumbled in the same problem with refresh, so I'm quite interested in this
> discussion. So, ok, I didn't know about flush() at all, but how do you
keep the
> http connection open in the first place? Just keep looping in the PHP or
is
> there a smarter way?

the 'smarter' way would be having a client side programming language open a
socket to the server (read: the php script running). the only realy useful
language is javascript becouse flash and java are not portable on some
platforms. the next problem is javascript isnt able (for security reasons)
to open a socket to the outside.

the only way to do (simplex) communication is to leave the http connection
open... by default, the connection is kept open until the php scripts
finishes (or die()'s). by looping php for a sertain amout of time we create
a 'stable' connection to the client.

an example (dont mind my crappy code format/indenting):

<html>
<body>
<?
// put a new row in /tmp/myfile?
if($new)
  {
  // yup, let us open a file (append modes) and write one line...
  $fp = fopen("/tmp/myfile", "a");
  fputs($fp, $new."\n");
  fclose($fp);
  // done, no code left for us, lets die
  }
else
  {
  // no new line, we are in viewing mode
  while(1 == 1)
    {
    // i feel looped :) open a file, again and again and again :)
    $file = file("/tmp/myfile");

    // if the file has more lines than the last time we opened it, we should
display some
    for($x=$filemax; $x < count($file); $x++)
      echo $file[$x]."<br>";
    // here we flush our send queue... the client is getting some data now
    flush();

    // count the number of lines we have displayed
    $filemax = count($file);
    // sleep! strange things are appenin' if we dont give a file time to
close when we are appending
    sleep(1);
    }
  }
?>
</body>
</html>

this example does _not_ handle any file locking and is _verry_ cpu/io
intensive. alot of other solutions could be uses including database query's
or shared memory

the next step is to build a nice interface for this, and maybe send some
'<script></script>' info instead of plain text

please mind, default php sets a timeout of 30 seconds for completing a php
script. ofcourse we can overrule that:

ini_set("max_execution_time", "3600");

another problem is proxy's and to slow connections, they will reset and your
client wont noice the page is not recieving data anymore... one of my
solutions is to just take resets for granted and build in a reload every 10
seconds with a html meta directive. if we use this we have a problem with
the sequenceing of the data: 'is our last row received'... a javascript
thingy could send a notice to the webserver the client recieved the line...

but thats a choice by the designer of a specific system, every chat has his
own needs of connection integrety.

hope my 5 euro cents help... :)

Joffrey van Wageningen
ne2000.nl


-- 
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]

Reply via email to