Skip to content

Commit

Permalink
Improved Socket Server for PHP 5.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
andot committed Jul 30, 2016
1 parent 4aff92f commit 93ae8bc
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Hprose/Socket/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* *
* hprose socket server library for php 5.3+ *
* *
* LastModified: Jul 30, 2016 *
* LastModified: Jul 31, 2016 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
Expand Down Expand Up @@ -60,10 +60,14 @@ private function createSocketServer($uri) {
$context = @stream_context_create($this->settings);
$server = @stream_socket_server($uri, $errno, $errstr,
STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context);
$socket = socket_import_stream($server);
socket_set_option($socket, SOL_SOCKET, SO_KEEPALIVE, (int)$this->keepAlive);
if ($scheme !== 'unix') {
socket_set_option($socket, SOL_TCP, TCP_NODELAY, (int)$this->noDelay);
if (function_exists('socket_import_stream')) {
if (($scheme === 'tcp') || ($scheme === 'unix')) {
$socket = socket_import_stream($server);
socket_set_option($socket, SOL_SOCKET, SO_KEEPALIVE, (int)$this->keepAlive);
if ($scheme === 'tcp') {
socket_set_option($socket, SOL_TCP, TCP_NODELAY, (int)$this->noDelay);
}
}
}
if ($server === false) {
throw new Exception($errstr, $errno);
Expand Down

0 comments on commit 93ae8bc

Please sign in to comment.