CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2008
    Posts
    15

    Question PHP socket keep alive.

    How to keep alive Socket in php? On user command disconnect?

    Senario 1:
    Client=======Server
    1. Connect send
    --------------->
    2. Ack Recv
    <---------------
    3. Echo/Primitive
    --------------->
    4. hh:mm minute
    processing....
    ----------------
    5. Status recv
    <---------------
    6. New command
    ---------------->
    7. Close on request
    ---------------->

    PHP Code:
    // Send Raw data over TCP
    $fp fsockopen ('212.58.58.58',5400$errno$errstr30);
    if (!
    $fp) {
    // Error
    } else {
    // 1st primitive
    fwrite($fp,$sends); //fixed
    echo hex4str (fread ($fp,256)); //read for debug
    // On recv data

    // close this session on command not automatic.
    fclose($fp);

    Last edited by PeejAvery; July 10th, 2008 at 12:36 PM. Reason: Added PHP tags.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP socket keep alive.

    In you PHP configuration file (php.ini is the default), change default_socket_timeout to a very large number of seconds. The default is 60.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jul 2008
    Posts
    15

    Question Re: PHP socket keep alive.

    This is increasing the auto connection close session lenght. But in client browser will this be real time send/recv processes ?

  4. #4
    Join Date
    Jul 2008
    Posts
    15

    Question Re: PHP socket keep alive.

    I would suggest instead of changing the default settings of the php.ini file, can i use ini_set() function which can be defined my page code. All i then do is change it to a really long amount of seconds, atleast the connection will not close, and then trying web page send/recv commands.

    ini_set( 'default_socket_timeout', xxxxx);

    what do you suggest?

  5. #5
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP socket keep alive.

    The setting is for the server. If you set it for 15 minutes, there is no way anyone is going to sit there and let your page go for that long. In essence, it would be like the connection never closes for the client.

    You can use ini_set(), but be aware of some server settings. If this is a hosted server from some company, most likely, you will not be able to alter the configuration using ini_set(). Instead, if you sign in to the account, they usually have a way to change the configuration file.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  6. #6
    Join Date
    Jul 2008
    Posts
    15

    Talking Re: PHP socket keep alive.

    Great, thanks a big.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured