Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Problem with permanent socket connection
- Ismail Demiralp
May 2, 2006, 11:38 am
rate this thread
I want to open a permanent socket connection to a service witch is running
on the same computer.
After I logged in on my php page, I start a session. After this a socket
connection should be opened to a service
I get data from. Now my problem is I want open only once a socket connection
to the service and after this I want use on
all php pages this connection. How can I transmit (or use) this one
connection on all pages ?
I opened the socket connection like this:
$fp = pfsockopen ($url, 1006, $errno, $errstr, 10);
This code snippet is running correctly, but on the next php page I can't use
Thanx for Help
Re: Problem with permanent socket connection
Write a daemon that opens this socket, then pass commands to the daemon
(maybe by signals, maybe using a socket) from PHP.
Have you read the comments on php.net:
OK, WRT to the p* functions opening a new connection when one already
exists. It is my understanting that (under Apache anyways) this is on a
per-process basis. If you do a 'ps auxw|grep httpd' on your server you
will see more than one process. What p* does is make a p-connection on one
of those processes only, the one that actually handles your request.
Chances are that when you hit the page again it will be answered by a
different process. I'm guessing if you keep hitting reload you'll get
around to the original process again and there will be no error message or
second connection open. Anyhow, this is true of all p* functions; they
open not one connection per server, but one connection per server _process_.
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos