PHP implementation of TCP port detection method, PHP implementation of TCP port _php tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.