Re: PHP and Connection: Close
| From: | Chris | Date: | Wed, 22 Mar 2006 00:45:27 +0000 |
| Subject: | Re: PHP and Connection: Close | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-232380@lists.php.net to get a copy of this message | ||
Jon Anderson wrote:
Chris wrote:If you're doing an exit() or die() or the script stops executing that's like you closing the connection - so apache is going to close the connection (as it should). -- Postgresql & php tutorials http://www.designmagick.com/That's the design of http - it's stateless. Each connection is treated separately and as such closes itself when it's finished. If you want to keep it open you'll need to create your own "service" that listens to a port and responds accordingly - which can be quite a lot of work. http://www.php.net/manual/en/ref.sockets.phpI can easily prove that HTTP can do it: Open a terminal or an SSH connection to a unix machine, then type: $ telnet <some web server> 80 GET / 1.1 Connection: Keep-Alive <server resonds, keeps connection open> GET / 1.1 Connection: Keep-Alive <server responds, keeps connection open> GET / 1.1 Connection: close <server responds, closes connection> Connections are capable of keeping themselves open for multiple requests - that's what "Connection: close" and "Connection: Keep-Alive" headers are for. For example http://webservices.codingtheweb.com/bin/qotd (with WSDL http://webservices.codingtheweb.com/bin/qotd.wsdl). If you open a connection to that with a soap client, you can make multiple requests to it. Trace it with ethereal or something, and you'll notice there's only one TCP connection setup (syn,syn/ack), followed by as many requests as you want, and eventually one TCP teardown (fin/ack,ack) if you set up the soap client to send a close request at some point. The example script above may not be PHP (I don't have the code, as it's not mine - just a random example), so for all I know PHP may not be capable of such a thing. It may even be a limitation of the web server (apache2) or the server's setup. (I just don't know, so that's why I'm asking here.)