summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <[email protected]>2019-10-28 01:05:10 +0100
committerSlávek Banko <[email protected]>2019-10-28 01:05:10 +0100
commit63a15aaa15e7d900b4e8d4dbfa8b560e58a5ed1e (patch)
tree7f88e4890bf5aa357c174b645cfe3d7b2fc84a7b
parent1890f10c40472c3600b10a4d8c86edb3c9ae3bf3 (diff)
downloadwebsite-core-63a15aaa15e7d900b4e8d4dbfa8b560e58a5ed1e.tar.gz
website-core-63a15aaa15e7d900b4e8d4dbfa8b560e58a5ed1e.zip
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 <[email protected]>
-rw-r--r--mirrorstatus.php36
1 files changed, 27 insertions, 9 deletions
diff --git a/mirrorstatus.php b/mirrorstatus.php
index b248140..12f2030 100644
--- a/mirrorstatus.php
+++ b/mirrorstatus.php
@@ -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']))
{