title: PHP websocket disconnect issue
body: <p>I've tested several libraries (<a href="https://github.com/walkor/Workerman" rel="nofollow noreferrer">workerman</a> and <a href="https://github.com/ghedipunk/PHP-Websockets" rel="nofollow noreferrer">PHP-Websockets</a>) but in all cases I have the same issue - when I open clients page everything is all right, I have websocket connection with my server, but later it disconnects automatically in a few minutes or less. Is it known issue or is there any methods to handle it? Or should I simply implement some function to force recconection if websocket fails?</p>
  
  <p>This is a code sample for <strong>workerman</strong></p>
  
  <p>Server <code>test_ws.php</code></p>
  
  <pre><code>&lt;?php
  require_once '/home/ubuntu/workspace/workerman/vendor/autoload.php';
  use Workerman\Worker;
  
  // Create a Websocket server
  $ws_worker = new Worker("websocket://0.0.0.0:8082");
  
  // 6 processes
  $ws_worker-&gt;count = 6;
  
  // Emitted when new connection come
  $ws_worker-&gt;onConnect = function($connection)
  {
      echo "New connection\n";
      $connection-&gt;send('Hello from server');
  };
  
  // Emitted when data received
  $ws_worker-&gt;onMessage = function($connection, $data)
  {
      // Send hello $data
      $connection-&gt;send('Data from server: ' . $data);
  };
  
  // Emitted when connection closed
  $ws_worker-&gt;onClose = function($connection)
  {
      echo "Connection closed\n";
  };
  
  // Run worker
  Worker::runAll();
  </code></pre>
  
  <p>And client <code>client.html</code></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var socket = new WebSocket("wss://example.com:8082");
          
  socket.onopen = function() {
     console.log("Connected.");
  };
  
  socket.onclose = function(event) {
     if (event.wasClean) {
        console.log('Connection closed');
     } else {
        console.log('Connection failure');
     }
     console.log('Code: ' + event.code + ' Reason: ' + event.reason);
  };
          
  socket.onmessage = function(event) {
     console.log("Data received: " + event.data);
  };
  
  socket.onerror = function(error) {
     console.log("Error: " + error.message);
  };
              
  function send() {
     socket.send("Hello!");
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
     &lt;meta charset="UTF-8"&gt;
     &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
     &lt;meta http-equiv="X-UA-Compatible" content="ie=edge"&gt;
     &lt;title&gt;Workerman Sockets Test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
     &lt;h3&gt;Hello&lt;/h3&gt;
     &lt;button onclick="send()"&gt;Send Message&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>So, at first I start apache server and then run my websocket script via console, websocket server starts fine. Then I open my client web page and websocket connection establishes fine too, but if I wait for about 1 minute or less it fails with no reason. How to establish permanent websocket connection? Any advise will be appreciated. Thanks!</p>
  
  <p><strong>Server</strong></p>
  
  <p><a href="https://i.stack.imgur.com/03LzT.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/03LzT.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Client</strong></p>
  
  <p><a href="https://i.stack.imgur.com/4d70k.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4d70k.jpg" alt="enter image description here"></a></p>