Ping multiple ip addresses at the same time to find the fastest php instance of the ip network-PHP source code

Source: Internet
Author: User
In this article, we will share a php program that can ping multiple ip addresses at the same time and then compare and find the fastest ip address in the network. This program is used to find the proxy ip address, but it is an artifact. In this article, we will share a php program that can ping multiple ip addresses at the same time and then compare and find the fastest ip address in the network. This program is used to find the proxy ip address, but it is an artifact.

Script ec (2); script


For the convenience of turning the wall, I bought a vpn and switched it to osx. The official website did not provide a suitable client, so I could not select the fastest line. So I wrote a script and manually pinged the fastest IP address.

The Code is as follows:
$ Servers = array (
Array ('vip Dutch line 01', 'nl01. yyuu. me', '81. 4.105.195 ', '2017 or 123 '),
Array ('vip French line 01', 'fr01. yyuu. me', '192. 31.206.242 ', '192, 176, 4122 '),
Array ('vip Italian line 01', 'it01. yyuu. me', '37. 247.48.226 ', '2017 or 123 '),
Array ('vip Singapore line 01', 'sg01. yyuu. me', '199.69.209 ', '2017 or 123 ')
);


// Used with pcntl_signal
Declare (ticks = 1 );
// Maximum number of sub-Processes
$ Max = count ($ servers );
// Current number of sub-Processes
$ Child = 0;

// This function is triggered when the sub-process exits.
Function sig_handler ($ sig ){
Switch ($ sig ){
Case SIGCHLD:
// Do something
}
}

// Register the function called when the sub-process exits
Pcntl_signal (SIGCHLD, "sig_handler ");
Foreach ($ servers as $ server ){
$ Pid = pcntl_fork ();
If ($ pid ){
// Echo 'main thread start', PHP_EOL;
} Else {
Exec ('Ping-c 1'. $ server [2], $ result );
Echo $ server [1]. ''. $ server [2].''. $ result [1], PHP_EOL;
Exit ();
}
}
Related Article

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.