How to keep a PHP socket client connection open until socket_closed() by user
<p>I have a button "connect" !
when i press that button i want to open a php socket connection to a ip:port and the connection should stay open to send and receive data messages until the users click;s disconnect. how can i do that? i have the following code:</p>

<pre><code>if (isset($_POST['cmd_connect'])) {
    // select in baza de date nodes pentru randul selectat de user
    $selectOption = $_POST['cmb_select_node'];
    $sqlquery = mysql_query("SELECT * FROM `nodes` WHERE node_mac='{$selectOption}'");
    if ($sqlquery === FALSE) {
        die(mysql_error());
    }
    while ($row = mysql_fetch_array($sqlquery)) {
        $host = $row['node_ip'];
        $port = 11000;
    };
    // don't timeout!
    set_time_limit(0);
        // Creaza si se connecteaza la socket internet IP

        $socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
        $s_connect=socket_connect($socket, $host, $port);
        $timeout= array('sec'=&gt;30,'usec'=&gt;500000);
        socket_set_option($socket, SOL_SOCKET , SO_KEEPALIVE, 1);
        socket_set_option($socket, SOL_SOCKET , SO_RCVTIMEO,$timeout);


        // Conditie creare si connectare socket
       if (! $socket) {
           ?&gt; &lt;script&gt;alert('Could not create the socket to client');&lt;/script&gt;
            &lt;?php
        } 
             elseif($s_connect) {
             ?&gt; &lt;script&gt;alert('Your Are now connected');&lt;/script&gt;
            &lt;?php
        }

    }


?&gt;
</code></pre>

<p>thanks</p>