logifuture
This commit is contained in:
1 parent
91ec9d11cc
commit
0e34020a01
22 files changed
+546
-442
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Utilities\Notice;
|
||||
use SimpleXMLElement;
|
||||
|
||||
class Xml
|
||||
{
|
||||
@@ -48,7 +49,7 @@ class Xml
|
||||
}
|
||||
}
|
||||
|
||||
$data = simplexml_load_file($url, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||
$data = self::fetch_data_with_retries($url);
|
||||
|
||||
if ($data === false && $debug) {
|
||||
Notice::note("Error: Failed to load XML from $url", 'r', 1);
|
||||
@@ -73,4 +74,35 @@ class Xml
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function fetch_data_with_retries($url, $max_retries = 3)
|
||||
{
|
||||
$attempt = 0;
|
||||
$timeout = 10; // seconds
|
||||
$connect_timeout = 5; // seconds
|
||||
|
||||
while ($attempt < $max_retries) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // Total timeout
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connect_timeout); // Connection timeout
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if ($response === false) {
|
||||
$attempt++;
|
||||
echo "Attempt $attempt failed. Retrying...\n";
|
||||
sleep(2); // Optional: Sleep between retries
|
||||
} else {
|
||||
curl_close($ch);
|
||||
|
||||
return new SimpleXMLElement($response);
|
||||
}
|
||||
}
|
||||
echo "All attempts failed.\n";
|
||||
curl_close($ch);
|
||||
|
||||
return null; // Return null if all retries fail
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user