Re: Full-duplex communication

From: Date: Thu, 23 May 2002 12:39:10 +0000
Subject: Re: Full-duplex communication
Groups: php.dev 
Request: Send a blank email to php-dev+get-84294@lists.php.net to get a copy of this message
Hi Faisal, Tx for ur thoughts... On Thu, 23 May 2002 Faisal Nasim wrote :
Hi, Why not simply use Apache to forward to the request to your PHP script or 'other program' and deploy threads for whatever process you want to run in the background?
I dont want to run anything else in the background. All i want to do is to have the ability to send some data to the client when it is required by the system.
Your program can keep sending the data and the threads will do the secondary work you want them to do.
Well, i can do the work in the PHP script that is being requested by the client also right? The client will be calling only php scripts all the time.
If the threads need to send the data to the connection as well, your PHP or other program should provide appropriate callback routines which will intercept the data from the threads.
Which php script will be running at the time? I'm talking about asynchronous events out here.
If you really need the socket, you'll probably need to make a Apache module and make it listen to the requests and do the work from the module itself.
Why should i go to the trouble of making an entire apache module that does the work? I'm using PHP scripts for my functionality and they are doing the job excellently. All i was trying to do is to make the process more efficient by having the ability to send data asynchronously without having the client poll for data all the time. Thats why i was wondering if apache might be giving some information to php regarding the socket so that i could retrieve it in my php script and store it for use later. Or if it is possible to write a php extension that would allow me to get the socket from apache and store it.
Good luck!
Tx, Vinod.
At 02:56 PM 5/23/2002, you wrote:
Hi Dave, Thanks for the suggestion. But i really dont wanna go in for an infinite loop - just a hopeless waste of resources. I didnt say that a Keep-Alive connection would mean a Full-Duplex connection - i know how keep-alive works, as well as HTTP. I know HTTP is based on a request-response model, and the server cannot send any data to the client without the client requesting for the data first. But what i want is the socket which is used by Apache to send data to the client, which is on a keep-alive connection, so that some other program, or a php script can send data asynchronously to the client. mind you, the client is a custom developed COM component, not a browser. So what i was asking for was a means to make the connection a Full-Duplex one, by taking the socket from apache and using it elsewhere. The Keep-alive timeouts can be configured at either ends since the web server is only going to be accessed by these clients. Tx, Vinod. On Wed, 22 May 2002 Dave Mertens wrote :
On Wed, May 22, 2002 at 10:16:23AM -0000, Vinod Panicker wrote:
The client calls a script on the server - script_a.php using
a
keep-alive connection. The script gets the socket from the
web
server (this is the unknown), and stores it in a database.
Script
finishes execution, client reads response, but apache doesnt
close
the connection since its keep-alive. Client wants to call another script on the server, just
writes to
the same socket. Script returns response. Server wants to send data asynchronously to the client, so a
PHP
script (invoked from another server) gets the socket of the
client
from the database and writes to it. Client reads from
the
socket. So this is basically a full-duplex connection over HTTP :)
Not quite! Keep-alive tries to keep a socket connection with the server, but this connection can only be used to request several resources from the servers (like the images inside a page). This because setting up a new tcp-connection takes a lot of time, keep-alive just reuse this connection for another request. The server itself cannot *start* sending data over the http connection, it can only reply on a client request. What you can do however, is to create a script with an endless loop, inside this loop the scripts looks if there's new data in a database and if there's data, it's sent to the client.. You can ofcourse also do other things inside the loop. But you won't need a keep-alive connection for this. Ohh, don't use any out buffering, otherwise the browser will timeout after 30 seconds.. ;-) However the server can't switch pages. What you can do, is inside the loop to access a different page with the fopen function. Hope this will answer your question, -- With best regards, Dave Mertens, Development Manager dmertens@ism.nl Innovative Solutions in Media BV Schiekade 101 3033 BG Rotterdam, Netherlands Tel. +31-10-2436060
_________________________________________________________ Click below to visit monsterindia.com and review jobs in India or Abroad http://monsterindia.rediff.com/jobs

« previous php.dev (#84294) next »