Created
January 21, 2016 16:15
-
-
Save EdwardIII/f7f8d23e8fdd87d1e3f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ini_set("default_socket_timeout", "1"); | |
class SocketWorker implements | |
{ | |
private $socketResource; | |
private $socketErrorNum; | |
private $socketErrorStr; | |
public function __construct($socketServer, $socketPort, $socketTimeOut) | |
{ | |
$this->socketResource = fsockopen($socketServer, $socketPort, $this->socketErrorNum, $this->socketErrorStr, $socketTimeOut); | |
return (!empty($this->socketResource)) ? true : false; | |
} | |
public function __destruct() | |
{ | |
$this->socketClose(); | |
} | |
public function socketRequest($socketRequest) | |
{ | |
$socketReturnByte = fwrite($this->socketResource, $socketRequest, strlen($socketRequest)); | |
return (!empty($socketReturnByte)) ? $socketReturnByte : false; | |
} | |
public function socketResponse() | |
{ | |
$socketResponse = ""; | |
while ($socketRead = fread($this->socketResource, 4096)) { | |
$socketResponse .= $socketRead; | |
} | |
return $socketResponse; | |
} | |
public function socketClose() | |
{ | |
fclose($this->socketResource); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment