Acorn Arcade forums: Programming: Persistant HTTP Connection w/ PHP
|
Persistant HTTP Connection w/ PHP |
|
Kinetic (13:40 5/5/2003) Hertzsprung (16:09 5/5/2003) Phlamethrower (22:43 5/5/2003)
|
|
Andrew Duffell |
Message #41226, posted by ad at 13:40, 5/5/2003 |
Posts: 3262
|
Does anyone know why the connection is not kept in this PHP code? The connection should stay open until it exits the loop, but it only stays open for the first connection :|
$kor = pfsockopen("kor.elogical.net",80, $errno, $errstr, 30); for($j=1;$j<$max;$j++){ fputs($kor, "GET http://kor.elogical.net/cgi-bin/search.pl?task=snum&num=".$j." HTTP/1.1\r\n". "Host: kor.elogical.net\r\n". "Cookie: user=death storm~pass=*****\r\n". "Connection: Keep-Alive\r\n\r\n"); } fclose($kor);
[Edited by Kinetic at 14:40, 5/5/2003] |
|
[ Log in to reply ] |
|
James Shaw |
Message #41230, posted by Hertzsprung at 16:09, 5/5/2003, in reply to message #41226 |
Ghost-like
Posts: 1746
|
Does anyone know why the connection is not kept in this PHP code? The connection should stay open until it exits the loop, but it only stays open for the first connection :|
$kor = pfsockopen("kor.elogical.net",80, $errno, $errstr, 30); for($j=1;$j<$max;$j++){ fputs($kor, "GET Hertzsprung at 17:14, 5/5/2003]
I think I've found a forum bug though :)
[Edited by Hertzsprung at 17:15, 5/5/2003]
[Edited by andypoole at 19:33, 5/5/2003. Turn smileys off when you are using code that could be converted to smileys]
[Edited by rich at 11:00, 6/5/2003. link weirdness]
|
|
[ Log in to reply ] |
|
Jeffrey Lee |
Message #41243, posted by Phlamethrower at 22:43, 5/5/2003, in reply to message #41226 |
Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot Hot stuff
Posts: 15100
|
*erases all his waffle and has another go*
First things first: Are you talking about connection in terms of a persistent TCP/IP connection (As opened by pfsockopen), or in terms of the requests being sent to the web server?
If it's in terms of the HTTP requests, then as far as I can tell 'Connection: Keep-Alive' is only a request and not a demand that the server must uphold; you need to check for a Connection: Keep-Alive header in the response to see if the server's listening (See http://www.io.com/~maus/HttpKeepAlive.html for some more info). Plus since HTTP 1.1 has keep-alive on by default, the connection: header seems a bit pointless (and might even be confusing the server or something)
If it's in terms of TCP/IP connections, then I don't think I can be of any help, as I've only used non-persistent ones myself. What I've found interesting is that the PHP manual page for fclose only mentions fopen() and fsockopen(), not pfsockopen()
Also on the pfsockopen page there is a mention of how you're supposed to save the file pointer and re-use it if possible since PHP won't re-use the connection for you. They do seem a bit undecisive about it though, and you'd also have the problem of trying to stop two concurrent versions of the script accessing the connection at the same time. The way I'd do it would be to save the file pointer and time it was opened/last used to disk. I.e. once a script has finished with a connection it appends it to open.txt, and whenever a script starts it loads open.txt, removes any connections which have timed out, removes and remembers a single connection which it's going to use, and then saves the remaining list of connections back to disk. This would require a bit of file locking jiggery, but it's probably to be expected if you try messing with persistent connections (Assuming the assumptions about the persistent file pointers is true).
Also looking at the bit of code you've got there, there isn't actually anything to read the data which you're being sent. Obviously that code would exist somewhere, but I'm thinking that if you try sending a load of requests in one go and then read the data at the end then the server might get a bit annoyed and disconnect you without sending much through. |
|
[ Log in to reply ] |
|
|
Acorn Arcade forums: Programming: Persistant HTTP Connection w/ PHP |