[PHP] PHP Chat REALTIME

2002-01-22 Thread Nuno Mariz

I need to build a php-chat (online support system), but in realtime.
I've develope a system that refresh in browser client in 5 seconds. But
i need a system that works in realtime, what i meen is when a client or
the server send a message, the browser refresh when a message was sent.
All this without JAVA.

thanx


-- 
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] PHP Chat REALTIME

2002-01-22 Thread Ben-Nes Michael

The server can controll the Refresh and the cache expiry through headers
sent when the page is requested by the client.

add this to expire client content every time a request for the same page is
sent.
header(Pragma: no-cache);

add this to refresh client content every 5 sec
meta http-equiv=Refresh
content=5;URL=http://www.doamin.com/page.phtml;.

--
Canaan Surfing Ltd.
Internet Service Providers
Ben-Nes Michael - Manager
Tel: 972-4-6991122
http://sites.canaan.co.il
--

- Original Message -
From: Nuno Mariz [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, January 22, 2002 12:32 PM
Subject: [PHP] PHP Chat REALTIME


 I need to build a php-chat (online support system), but in realtime.
 I've develope a system that refresh in browser client in 5 seconds. But
 i need a system that works in realtime, what i meen is when a client or
 the server send a message, the browser refresh when a message was sent.
 All this without JAVA.

 thanx


 --
 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] PHP Chat REALTIME

2002-01-22 Thread Nuno Mariz

That was not the problem, i need something that keep the conection
between client and server.

On Tue, 2002-01-22 at 10:51, Ben-Nes Michael wrote:
 The server can controll the Refresh and the cache expiry through headers
 sent when the page is requested by the client.
 
 add this to expire client content every time a request for the same page is
 sent.
 header(Pragma: no-cache);
 
 add this to refresh client content every 5 sec
 meta http-equiv=Refresh
 content=5;URL=http://www.doamin.com/page.phtml;.
 
 --
 Canaan Surfing Ltd.
 Internet Service Providers
 Ben-Nes Michael - Manager
 Tel: 972-4-6991122
 http://sites.canaan.co.il
 --
 
 - Original Message -
 From: Nuno Mariz [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Tuesday, January 22, 2002 12:32 PM
 Subject: [PHP] PHP Chat REALTIME
 
 
  I need to build a php-chat (online support system), but in realtime.
  I've develope a system that refresh in browser client in 5 seconds. But
  i need a system that works in realtime, what i meen is when a client or
  the server send a message, the browser refresh when a message was sent.
  All this without JAVA.
 
  thanx
 
 
  --
  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]
 
 
 
-- 

  Nuno  Mariz
 Web Developer

WEBSOLUT - Soluções Internet
Email: [EMAIL PROTECTED]
http://websolut.net/people/nunomariz.html

As informações contidas neste email são confidenciais
para todos os efeitos e destinam-se apenas a quem foi enviado:
http://websolut.net/confidencialidade-responsabilidade.html


--
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] PHP Chat REALTIME

2002-01-22 Thread Ben-Nes Michael

I dont think its possible without Java programing.

If there is other solutions ill be glad to hear.
--
Canaan Surfing Ltd.
Internet Service Providers
Ben-Nes Michael - Manager
Tel: 972-4-6991122
http://sites.canaan.co.il
--

- Original Message -
From: Nuno Mariz [EMAIL PROTECTED]
To: Ben-Nes Michael [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Tuesday, January 22, 2002 1:02 PM
Subject: Re: [PHP] PHP Chat REALTIME


That was not the problem, i need something that keep the conection
between client and server.

On Tue, 2002-01-22 at 10:51, Ben-Nes Michael wrote:
 The server can controll the Refresh and the cache expiry through headers
 sent when the page is requested by the client.

 add this to expire client content every time a request for the same page
is
 sent.
 header(Pragma: no-cache);

 add this to refresh client content every 5 sec
 meta http-equiv=Refresh
 content=5;URL=http://www.doamin.com/page.phtml;.

 --
 Canaan Surfing Ltd.
 Internet Service Providers
 Ben-Nes Michael - Manager
 Tel: 972-4-6991122
 http://sites.canaan.co.il
 --

 - Original Message -
 From: Nuno Mariz [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Tuesday, January 22, 2002 12:32 PM
 Subject: [PHP] PHP Chat REALTIME


  I need to build a php-chat (online support system), but in realtime.
  I've develope a system that refresh in browser client in 5 seconds. But
  i need a system that works in realtime, what i meen is when a client or
  the server send a message, the browser refresh when a message was sent.
  All this without JAVA.
 
  thanx
 
 
  --
  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]
 
 

--

  Nuno  Mariz
 Web Developer

WEBSOLUT - Soluções Internet
Email: [EMAIL PROTECTED]
http://websolut.net/people/nunomariz.html

As informações contidas neste email são confidenciais
para todos os efeitos e destinam-se apenas a quem foi enviado:
http://websolut.net/confidencialidade-responsabilidade.html


--
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] PHP Chat REALTIME

2002-01-22 Thread Joffrey van Wageningen

 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)

shoplist for a chat:
* 3 frames: 1 to display incomming data, 1 to have a input field and post to
the server and 1 to receive data from your http stream (could be hidden)

* some javascript to move the data from the http stream window to the
display window

* a db backend and maybe a check (with the post, or the refresh) which lines
have been received by the client

* a cute design :)

with kind regards,
Joffrey van Wageningen
ne2000.nl





Re: [PHP] PHP Chat REALTIME

2002-01-22 Thread Bogdan Stancescu

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?

Bogdan

Joffrey van Wageningen wrote:

  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)

 shoplist for a chat:
 * 3 frames: 1 to display incomming data, 1 to have a input field and post to
 the server and 1 to receive data from your http stream (could be hidden)

 * some javascript to move the data from the http stream window to the
 display window

 * a db backend and maybe a check (with the post, or the refresh) which lines
 have been received by the client

 * a cute design :)

 with kind regards,
 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]




Re: [PHP] PHP Chat REALTIME

2002-01-22 Thread Joffrey van Wageningen

   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]




[PHP] PHP Chat REALTIME

2002-01-22 Thread Joffrey van Wageningen

i forgot to mention in my last code sniplet:

just run the script (maybe touch a new file in /tmp and give it readwrite
rights)... you will have a run for 30 seconds (the php timeout)

if you want to add a line edit the file manualy or use the sniplet:

sniplet.php?new=mynewline

:)


-- 
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] PHP Chat REALTIME

2002-01-22 Thread Bogdan Stancescu

 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.

Been there, done that (i.e. already thought about these).

 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.

Been here too - that's why my original question looks the way it does. So, the
answer is actually No, there's no smarter way than looping in the PHP - am I
correct?

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

 $file = file(/tmp/myfile);
 for($x=$filemax; $x  count($file); $x++)
   echo $file[$x].br;

I especially liked the bit above. Never used file() myself so the code looked
quite awkward at first glance...

 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

Another feature of PHP I always overlooked! I'm learning of a lot of overlooked
features from your e-mail!

 ini_set(max_execution_time, 3600);

You could also do a set_time_limit(30) INSIDE the loop. This resets the timeout
counter, so it's a better option.

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

...which further speeds down the overall process, plus induces a lot of delays
which have to be dealt with (quite complicated, I must say). I think simply
reloading from time to time and sending the last 10 lines for example might be a
better solution.

 hope my 5 euro cents help... :)

Yes, they did - you opened my eyes to a couple of useful but neglected features
of PHP.

Thanks for taking the time to answer!

Bogdan




-- 
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] PHP Chat REALTIME

2002-01-22 Thread Joffrey van Wageningen

 i haven't been following this, but have you guys thought of ircg?
 http://php.net/ircg

ircg is a lot of fun and could be used as the server system for message
management, the real problem is how to get the data  to the client without
use of a socket

ircg also needs an ircd which is a little to bloated[1] for a simple
solution for a realtime chat :)

/me is taking a extra jolt on ircg :)

Joffrey van Wageningen
ne2000.nl
--
[1]
bloat·ed (bltd)
adj.
  1.. Much bigger than desired: a bloated bureaucracy; a bloated budget.
  2.. Medicine. Swollen or distended beyond normal size by fluid or gaseous
material.




Re: [PHP] PHP Chat REALTIME

2002-01-22 Thread Joel Boonstra

 I need to build a php-chat (online support system), but in realtime.
 I've develope a system that refresh in browser client in 5 seconds. But
 i need a system that works in realtime, what i meen is when a client or
 the server send a message, the browser refresh when a message was sent.
 All this without JAVA.

Have you thought about using a pre-built system:

  http://www.phplivesupport.com/web/phplive_web/

It does cost money (one-time fee, no recurring fee), but I would imagine
that spending time to build one yourself would also cost money (in terms
of time).

I have never used it, but it definitely looks to be worthwhile.

-- 
[ joel boonstra | [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] PHP Chat REALTIME

2002-01-22 Thread Rodolfo Gonzalez

On Tue, 22 Jan 2002, Joffrey van Wageningen wrote:
 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.

But it would be better to have just a server written in C/C++/whatever and
then a Java applet to connect to the server from the browser, just as
almost every chat around the www do (even an IRC server would do the job
propperly secured). Disadvantages:  the browser must support Java applets
(not a big deal anyway, since with an HTML chat you'll most likely need
frames). I see this solution simpler.

Regards.





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