By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,824 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,824 IT Pros & Developers. It's quick & easy.

Problem with permanent socket connection

P: n/a
Hi,

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
this connection.

Thanx for Help

May 2 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Tue, 02 May 2006 13:38:59 +0200, Ismail Demiralp wrote:
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 ?
Write a daemon that opens this socket, then pass commands to the daemon
(maybe by signals, maybe using a socket) from PHP.
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 this connection.


Have you read the comments on php.net:

http://uk2.php.net/pfsockopen

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_.
Cheers,
Andy
--
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

May 2 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.