2016-01-25 25 views
8

私は奇妙な問題があると私は、溶液または私が午前問題に近い何かを見つけることができないよう、ここでPHP TCPソケット接続制限 - Windowsサーバ

事ですが、私はscoketスクリプトを持っていますコマンドラインでphp経由で実行すると、接続を受け取り、モバイルアプリケーションクライアントからjson形式のデータを読み込み、jsonで適切な応答を送信します。

接続数が256接続を超えない限り、すべて正常に動作します。

私はその理由を知りたいのですが、どのように解決できますか?私はずっとずっとそれをしてきましたが、運はありません!ここで

はスクリプトである私が話題にされており、大規模な検索を行なったし、これらの、 http://smallvoid.com/article/winnt-tcpip-max-limit.htmlと2ダースの他のような記事を渡った何

<?php 

date_default_timezone_set("UTC"); 
$server = stream_socket_server("tcp://192.168.1.77:25003", $errno, $errorMessage); 

if (!$server) { 
    die("$errstr ($errno)"); 
} 

echo "Server started.."; 
echo "\r\n"; 

$client_socks = array(); 

while (true) { 
    //prepare readable sockets 
    $read_socks = $client_socks; 
    $read_socks[] = $server; 

    //start reading and use a large timeout 
    if (!stream_select ($read_socks, $write, $except, 10000)) { 
     die('something went wrong while selecting'); 
    } 

    //new client 
    if (in_array($server, $read_socks)) { 
     $new_client = stream_socket_accept($server); 

     if ($new_client) { 
      //print remote client information, ip and port number 
      echo 'Connection accepted from ' . stream_socket_get_name($new_client, true); 
      echo "\r\n"; 

      $client_socks[] = $new_client; 
      echo "Now there are total ". count($client_socks) . " clients"; 
      echo "\r\n"; 
     }   

     // echo stream_socket_get_name($new_client, true); 
     //delete the server socket from the read sockets 
     unset($read_socks[array_search($server, $read_socks)]); 
    } 

    $data = ''; 
    $res = ''; 

    //message from existing client 
    foreach($read_socks as $sock) { 
     stream_set_timeout($sock, 1000); 
     while($resp = fread($sock, 25000)) { 
      $data .= $resp; 
      if (strpos($data, "\n") !== false) { 
       break; 
      } 
     } 

     $info = stream_get_meta_data($sock);  

     if ($info['timed_out']) { 
      unset($client_socks[array_search($sock, $client_socks)]); 
      @fclose($sock); 
      echo 'Connection timed out!'; 
      continue; 
     }  

     $client = stream_socket_get_name($sock, true); 

     if (!$data) { 
      unset($client_socks[array_search($sock, $client_socks)]); 
      @fclose($sock);   

      echo "$client got disconnected"; 
      echo "\r\n"; 
      continue; 
     } 

     //send the message back to client 
     $decode = json_decode($data); 


     $encode = json_encode($res); 
     fwrite($sock,$encode."\n");  
    } 
} 

P.Sを:スニペット。

私はそれはあなたのコードとは何の関係もいません5.5.12

+0

ここには、コマンドプロンプトのスクリーンショットがあります。http://prntscr.com/9ul9yh –

+0

あなたが引用した記事の一番下にあるリンクをたどっていないという恥があります。http://smallvoid.com/article/winnt- network-connection-limit.html – symcbean

+0

バディ、私は実際にやったと私は言及Dの単語を追加することに疲れました。しかし使用はありません!私はあなたが助けることができるサーバーとしてWindows 8を使用していますか? –

答えて

0

をPHP実行します。この事+ WAMP 2.5を実行しているWindows 7を持っている、それはあなたがサーバー版を購入するためにMSのWindowsの「機能」だ(または別のOSにアップグレードしてください)。機能的には、NTカーネルのサーバー版とデスクトップ版の間に違いはありませんが(いくつかの最適化の調整があります)、ライセンスの条件を遵守していることを確認する手段に過ぎません。

+0

私はAzureからWindowsサーバでこの同じことを実際に試しました。同じことです!仕様書や何かを探すべきサーバーの種類は? –

+1

@DragonWarrior Get linux;)IISは、IISを実行するつもりがない場合、サーバーにとって無用です。 – RandomSeed