PHP implementation of TCP port detection method, PHP implementation of TCP port
This paper describes the method of implementing TCP port detection in PHP. Share to everyone for your reference. Specific as follows:
The program can confirm that the current port is available:
<?phpclass Health {public static $status; Public function __construct () { } public function check ($IP, $port) { $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), 5); Return (self:: $status); } Public Function Checklist ($LST) { } public function status () { switch (self:: $status) { case 2: echo "closed\n"; break; Case 1: echo "openning\n"; break; Case 0: echo "timeout\n"; Break;}}} $ip = ' 192.168.2.10 '; $port =80; $health = new Health (); $health->check ($ip, $port); $health->status ();
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/977787.html www.bkjia.com true http://www.bkjia.com/PHPjc/977787.html techarticle PHP Implementation of TCP port detection method, PHP implementation of TCP port in this paper, the implementation of PHP TCP port detection method. Share to everyone for your reference. As follows: The program can confirm ...