Adjustments for detecting mirrors status

+ Curl-multi is used for asynchronous testing of mirrors.
+ Timeout for curl requests increased to 10 seconds.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
vps
Slávek Banko 5 years ago
parent 1890f10c40
commit 63a15aaa15
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -27,6 +27,8 @@
$redis = new Redis();
$redis->connect('127.0.0.1', 6379, 2);
$ch = array();
$cmh = curl_multi_init();
foreach( $mirrors as $mirrorName => $mirrorInfo )
{
$savedResult = $redis->isConnected() ? $redis->get('mirrorStatus-'.$mirrorName) : false;
@ -36,14 +38,29 @@
}
else
{
$cs = curl_init();
curl_setopt( $cs, CURLOPT_URL, $mirrorInfo['url'].'-synctime' );
curl_setopt( $cs, CURLOPT_TIMEOUT, 3 );
curl_setopt( $cs, CURLOPT_HEADER, true );
curl_setopt( $cs, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $cs, CURLOPT_RETURNTRANSFER, true );
$ret = curl_exec( $cs );
curl_close( $cs );
$ch[$mirrorName] = curl_init();
curl_setopt( $ch[$mirrorName], CURLOPT_URL, $mirrorInfo['url'].'-synctime' );
curl_setopt( $ch[$mirrorName], CURLOPT_TIMEOUT, 10 );
curl_setopt( $ch[$mirrorName], CURLOPT_HEADER, true );
curl_setopt( $ch[$mirrorName], CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch[$mirrorName], CURLOPT_RETURNTRANSFER, true );
curl_multi_add_handle( $cmh, $ch[$mirrorName] );
}
}
if(!empty($ch))
{
$running = null;
do
{
curl_multi_exec($cmh, $running);
}
while($running);
foreach( $ch as $mirrorName => $cs )
{
$ret = curl_multi_getcontent( $cs );
curl_multi_remove_handle( $cmh, $cs );
if(!empty( $ret ))
{
if(!preg_match('#(^|\n)HTTP/1.1 200 OK#', $ret))
@ -67,6 +84,8 @@
}
}
}
curl_multi_close($cmh);
$redis->close();
foreach( $mirrors as $mirrorName => $mirrorInfo )
{
@ -107,7 +126,6 @@
}
}
}
$redis->close();
if(!isset($_GET['mr']))
{

Loading…
Cancel
Save