- class Health {
- public static $status;
- public function __construct() {
- }
- public function check($ip, $port, $timeout = 2){
- $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
- socket_set_nonblock($sock);
- socket_connect($sock,$ip, $port);
- socket_set_block($sock);
- self::$status = socket_select($r = array($sock), $w = array($sock), $f = array($sock), 2);
- return(self::$status);
- }
- public function status(){
- switch(self::$status)
- {
- case 2:
- return "Closed";
- break;
- case 1:
- return "Openning";
- break;
- case 0:
- return "Closed";
- break;
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/2605201512658.html
来源: http://www.codesnippet.cn/detail/2605201512658.html