This article illustrates the method of implementing TCP port detection in PHP. Share to everyone for your reference. Specifically as follows:
The program can confirm that the current port is available:
1, 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<?php class 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 "closedn"; 1:echo "OPENNINGN"; Break Case 0:echo "TIMEOUTN"; Break }} $ip = ' 192.168.2.10 '; $port = 80; $health = new Health (); $health->check ($ip, $port); $health->status (); |