Ping multiple IP at the same time to find the fastest IP network PHP instance

Source: Internet
Author: User


In order to turn the wall convenient, bought a VPN, go to OS X below the official did not provide the right client, can not choose the fastest line. So he wrote a script, manually ping the fastest IP.

The code is as follows Copy Code
$servers = Array (
Array (' VIP Dutch line ', ' nl01.yyuu.me ', ' 81.4.105.195 ', ' 4122 or 3108 '),
Array (' VIP French Line ', ' fr01.yyuu.me ', ' 176.31.206.242 ', ' 4122 or 3108 '),
Array (' VIP Italian Line ', ' it01.yyuu.me ', ' 37.247.48.226 ', ' 4122 or 3108 '),
Array (' VIP Singapore line ', ' sg01.yyuu.me ', ' 128.199.69.209 ', ' 4122 or 3108 ')
);


Cooperate with pcntl_signal to use
Declare (Ticks=1);
Maximum number of child processes
$max = count ($servers);
Current number of child processes
$child = 0;

This function is triggered when a child process exits
function Sig_handler ($sig) {
Switch ($SIG) {
Case SIGCHLD:
Do something
}
}

function to call when registering child 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 ();
}
}

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.