473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

PHP & open connections

I'd like to create a simple chat application that will leave the
connection open for a minute and then restart the connection to the
server to push data. I plan to use temporary .txt files to store
messages. My question is how can I do that in PHP 5, what techniques
should I do server-side to keep this connection open and how would be
the flow of the message? Do I need a different technology such as
Python to handle messages?

1. User A sends a message to the server
2. ?
3. User B receives the message instantly through an open connection

Any tip/link/tutorial would be greatly appreciated.
Thanks,

Lenard.

Oct 2 '06 #1
7 1608
Lenard Redwood wrote:
I'd like to create a simple chat application that will leave the
connection open for a minute and then restart the connection to the
server to push data. I plan to use temporary .txt files to store
messages. My question is how can I do that in PHP 5, what techniques
should I do server-side to keep this connection open and how would be
the flow of the message? Do I need a different technology such as
Python to handle messages?

1. User A sends a message to the server
2. ?
3. User B receives the message instantly through an open connection

Any tip/link/tutorial would be greatly appreciated.
Thanks,

Lenard.
You can't. HTTP is a pull only protocol. You can use javascript on the
client to pull the info on a regular basis (i.e. every 30 seconds). But
you can't push the data out.

The other alternative is something like a Java applet where you can
maintain a connection.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 2 '06 #2
Jerry Stuckle wrote:
You can't. HTTP is a pull only protocol. You can use javascript on the
client to pull the info on a regular basis (i.e. every 30 seconds). But
you can't push the data out.
Exactly, actually each time user A writes a message and hits "Enter" it
is sent right away to the server. But how can this message be thrown
into the open connection that user B is using?
Thanks,

Lenard

Oct 2 '06 #3
Lenard Redwood wrote:
Jerry Stuckle wrote:
>>You can't. HTTP is a pull only protocol. You can use javascript on the
client to pull the info on a regular basis (i.e. every 30 seconds). But
you can't push the data out.


Exactly, actually each time user A writes a message and hits "Enter" it
is sent right away to the server. But how can this message be thrown
into the open connection that user B is using?
Thanks,

Lenard
That's what I'm saying. You can't with the http protocol. It's not
designed for that.

Use javascript to update regularly or another tool such as java which
can define its own protocol (java on the server and an applet on the
client).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 2 '06 #4
"Lenard Redwood" <fr***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Jerry Stuckle wrote:
>You can't. HTTP is a pull only protocol. You can use javascript on the
client to pull the info on a regular basis (i.e. every 30 seconds). But
you can't push the data out.

Exactly, actually each time user A writes a message and hits "Enter" it
is sent right away to the server. But how can this message be thrown
into the open connection that user B is using?
Thanks,

Shared Memory Functions
http://fi.php.net/manual/en/ref.shmop.php

Both clients share a memoryblock where messages are read and written. You
might need of course some sort of locking system. When recieving the
message, the script tries to set it's semaphore in the memoryblock, then
test if it got it, then write to it, then release the semaphore and raise a
flag indicating that there is a new message waiting for the other
participant.

Both connections should be kept alive all the time, sending empty spaces
every now and then should keep it alive. Time-outing must be disabled of
course. I think it could work. It would be fun to develope. I've never used
shmop thou, so I might be wrong, but that's the closest thing php has to
"threads" AFAIK.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)
Oct 3 '06 #5
Kimmo Laine wrote:
"Lenard Redwood" <fr***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>>Jerry Stuckle wrote:
>>>You can't. HTTP is a pull only protocol. You can use javascript on the
client to pull the info on a regular basis (i.e. every 30 seconds). But
you can't push the data out.

Exactly, actually each time user A writes a message and hits "Enter" it
is sent right away to the server. But how can this message be thrown
into the open connection that user B is using?
Thanks,

Shared Memory Functions
http://fi.php.net/manual/en/ref.shmop.php

Both clients share a memoryblock where messages are read and written. You
might need of course some sort of locking system. When recieving the
message, the script tries to set it's semaphore in the memoryblock, then
test if it got it, then write to it, then release the semaphore and raise a
flag indicating that there is a new message waiting for the other
participant.

Both connections should be kept alive all the time, sending empty spaces
every now and then should keep it alive. Time-outing must be disabled of
course. I think it could work. It would be fun to develope. I've never used
shmop thou, so I might be wrong, but that's the closest thing php has to
"threads" AFAIK.
Shared memory isn't the problem. The problem is you cannot keep the
connection open.

Sending spaces will keep it open for a bit - but that means keeping your
php code running all the time. And you can't do that unless you set the
timeout parameter to a very large value. And that's not a good idea -
what happens if another script starts looping, for instance.

Even then the browser and/or server are free to close the connection if
they feel it's been open too long, and most browsers will have a limit
as to how long they will wait for data (even if some is still coming
down the pipe).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 3 '06 #6
How about keeping the connection open for a minute, then reopen it?

Services like Gtalk (http://mail.google.com/mail/help/chat.html),
Interaction (http://www.interactionchat.com/) and Meebo
(http://www.meebo.com/) use an open-connection and this allows
reception of new messages instantly without the need of a Java applet
or a Flash application. There's gotta be a way...

Oct 3 '06 #7
Lenard Redwood wrote:
How about keeping the connection open for a minute, then reopen it?

Services like Gtalk (http://mail.google.com/mail/help/chat.html),
Interaction (http://www.interactionchat.com/) and Meebo
(http://www.meebo.com/) use an open-connection and this allows
reception of new messages instantly without the need of a Java applet
or a Flash application. There's gotta be a way...
I don't know about Gtalk - I don't do Gmail, so I don't know how they do it.

Interactionchat and Meebo both use Ajax, so I suspect they're using
javascript to poll the server.

No, there is absolutely no way - nada - zip - zero to the infinite power
- way to "push" data with the http protocol. It is strictly a
request/response protocol, with the request initiated by the client.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 3 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Daniel Ruscoe | last post by:
Hi chaps, I'm relatively new to the language, but I want to create a simple order form using PHP and cookies. Please let me know if there's a better way in this situation, database isn't...
1
by: flupke | last post by:
Hi, i'm trying to convert my java console app to a python gui. Now, the only problem i seem to have at the moment are the resizers for the layout. It seems that for the purpose of what i'm...
5
by: Lauren Wilson | last post by:
Hi folks, Somewhere, I recently saw an article header titled: "How to compact and Repair a back-end Access db from the front-end using VBA" or words to that effect. Now that I need it, I...
1
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and...
10
by: Shaniqua Jones | last post by:
I've designed a C# application consisting of two EXEs: a client and server. The server runs on my Win2000 Server box, and the client runs on my customers' machines -- typically XP. The client app...
0
by: ʹÃûÑï | last post by:
ORA-03114: not connected to ORACLE && MS's Bug?? DataBase:Oracle 817 using OracleClient,net framework 1.1 I'm using ADO.Net in C# with Oracle 817. and following is my public data access...
4
by: Jon Maz | last post by:
Hi, I just read the following in an old NG thread: "when you use the adapter with a closed connection it will open it, do your requested database access, and close it immediately. If you use...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
5
by: Usman Jamil | last post by:
Hi I've a class that creates a connection to a database, gets and loop on a dataset given a query and then close the connection. When I use netstat viewer to see if there is any connection open...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.