thorpe wrote:Your using the wrong proticol if your trying to maintain a connection via HTTP. HTTP is stateless and not designed to maintain a connection between client / server.
To do this sort of thing you would need to make a client and a server using sockets. Of course, this doesn't really sound like it would meet your needs though.
Can you explain in a little more detail what it is your trying to do and why?
I'm very aware that sockets would be the easy way out, but I can't afford to do this with sockets. I intend to write a Gnutella Server in PHP, this server responds to magnet link requests. File transfers in Gnutella occurr using HTTP/1.1, If you read about HTTP/1.1 it introduces the concept of Persistent Connections
Persistent Connections
HTTP/1.0, in its documented form, made no provision for persistent connections. Some HTTP/1.0 implementations, however, use a Keep-Alive header (described in [Fie95]) to request that a connection persist. This design did not interoperate with intermediate proxies (see Section 19.6.2 of [FGM+98]); HTTP/1.1 specifies a more general solution.
In recognition of their desirable properties, HTTP/1.1 makes persistent connections the default. HTTP/1.1 clients, servers, and proxies assume that a connection will be kept open after the transmission of a request and its response. The protocol does allow an implementation to close a connection at any time, in order to manage its resources, although it is best to do so only after the end of a response.
Because an implementation may prefer not to use persistent connections if it cannot efficiently scale to large numbers of connections or may want to cleanly terminate one for resource-management reasons, the protocol permits it to send a Connection: close header to inform the recipient that the connection will not be reused.
It's a shame most people out there (and let's hope not PHP architects) are still thinking that all communication between browser and server has to be just one request and response, the cost of openning new connections is costly.
So answering more in detail, here's what happens.
When a Gnutella client requests a magnet, it sends a HEAD request to whoever has the magnet, here it will wait only for HEADERS that will tell it information about the file. Once it receives the headers from the server, it answers right back with GET requests, this get requests take advantage of the new 'Range' headers, which allow asking for byte ranges of the file, then the server must respond with 206 Partial content, and serve the desired part of the file, once its served, the Gnutella client could ask for another part, and so on, until it's satisfied.
I need to get a hold of the socket that's open as you see, I need to know how to get the input stream and output stream of the php page, this must be possible, but it seems like this is a question none can answer but the php team, everyone tends to think I'm naive and answer the way you did.
Hope you can help me find an answer.
If I can manage to do this, I think I'll be able to ignite a hughe fire on the internet, many webmasters that are allowed to run PHP, but no servers could take advantage of a network like gnutella, just by sharing files or folders and adding magnet links to its pages, no trackers, no .torrents, all they'll need will be my scripts and add magnet links to the files they want to share. Both the Gnutella network and web masters will be benefited by this.
Hope anyone is interested in helping on this quest, I plan to release my code under the GPL.