Problem with permanent socket connection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ismail Demiralp

    Problem with permanent socket connection

    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



  • Andy Jeffries

    #2
    Re: Problem with permanent socket connection

    On Tue, 02 May 2006 13:38:59 +0200, Ismail Demiralp wrote:[color=blue]
    > 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 ?[/color]

    Write a daemon that opens this socket, then pass commands to the daemon
    (maybe by signals, maybe using a socket) from PHP.
    [color=blue]
    > 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.[/color]

    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_.


    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

    Comment

    Working...