To change the maximum allowed backlog by your system (*nix machines only), first you need to find the variable for this limit:
sudo sysctl -a | grep somaxconn
On ubuntu boxes, it returns net.core.somaxconn (you need to look for the 'somaxconn' variable, the full name will vary across different systems).
Update this to a large number as follows:
sudo sysctl -w net.core.somaxconn=1024
This will work straight away. no restart required.
socket_listen
(PHP 4 >= 4.1.0, PHP 5)
socket_listen — ソケット上で接続待ち(listen)する
説明
ソケット socket が socket_create() を用いて作成され、 socket_bind() で名前が付けられた後、 socket 上の接続要求を待つための通信ができるようになります。
socket_listen() は、ソケットが SOCK_STREAM 型または SOCK_SEQPACKET 型の場合のみ利用可能です。
パラメータ
- socket
-
socket_create() で作成したソケットリソース。
- backlog
-
最大 backlog 個の接続を処理用の キューで待ち受けることが可能です。もし待ちうけ用のキューが いっぱいになった場合、クライアントでは ECONNREFUSED の通知とともにエラーが発生します。あるいは、もし基盤となるプロトコルが リクエストの再送をサポートしている場合、再試行が成功するまで リクエストは無視されます。
注意: backlog パラメータに指定できる値の最大値は プラットフォームに大きく依存します。Linux では、最大値は SOMAXCONN に切り詰められます。win32 では、 もし SOMAXCONN を渡した場合、backlog の 最大値を適切な値に設定する責任はサービスの 提供側が負います。 このプラットフォームでは、実際の backlog の値を見つける標準的な 手段が提供されていません。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。 エラーコードは socket_last_error() で取得可能で、このコードを socket_strerror() に指定することにより エラーの内容を文字列として取得可能です。
参考
- socket_accept() - ソケットへの接続を許可する
- socket_bind() - ソケットに名前をバインドする
- socket_connect() - ソケット上の接続を初期化する
- socket_create() - ソケット(通信時の終端)を作成する
- socket_strerror() - ソケットエラーの内容を文字列として返す
socket_listen
16-Jul-2008 02:10
30-Aug-2005 10:13
socket_listen() cannot be used for UDP communications as discussed below.
In addition, the example below discusses UDP connections, which only exist if the application manages them through a state table (the OS does not create a UDP connection upon receiving a datagram). Having a function named socket_connect() that determines the remote IP and port only confuses the matter by giving the indication of some sort of connection handshake between two hosts. Rather, socket_connect() only specifies the remote IP and port used by subsequent socket_send() calls. You can achieve the same effect by skipping socket_connect() altogether and specifying the remote IP and port in socket_sendto() calls.
If you find yourself writing a connection-based protocol on top of UDP, consider using TCP. If your application requires streaming data of some sort, use TCP to manage connections and control messages, and UDP to handle the streaming data (H.323 is an example of a suite of TCP and UDP protocols working in conjunction).
