logifuture

This commit is contained in:
salam committed 2026-01-07 19:45:33 +01:00
1 parent 91ec9d11cc
commit 0e34020a01
22 files changed
+546 -442

No files matched your search

+76 -39
View File
@@ -16,9 +16,10 @@ class Curl
$proxy = Nuh::$options['p'] ?? 0;
if ($debug) {
Notice::note($url, 'g');
if ($proxy) {
Notice::note(Nuh::$options['proxy'], 'r');
Notice::note($url.PHP_EOL.Nuh::$options['proxy'], 'b');
} else {
Notice::note($url, 'g');
}
}
@@ -32,44 +33,8 @@ class Curl
return json_decode($file, true);
}
if ($proxy) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, Nuh::$options['proxy']);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['url' => $url]);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Proxy-Auth: AIkcoRnipSgMK88WMQhOQQN3LKDrNDCIebNfPnEayJdmDeTigx',
]);
} else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
// POST
if (isset($_config['post'])) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($_config['post']));
}
// JSON
if (isset($_config['header'])) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $_config['header']);
}
}
$file = curl_exec($ch);
$curl_errorno = curl_errno($ch);
if ($curl_errorno) {
Notice::note('curl_errorno: '.self::curlerrorcode($curl_errorno));
}
$file = self::fetch_data_with_retries($url, $_config);
if ($save) {
$filename = app_path().self::$testfiles.strtolower(str_replace(' ', '_', Nuh::$options['name'])).'.json';
@@ -102,6 +67,78 @@ class Curl
return $data;
}
public static function fetch_data_with_retries($url, $_config = [], $max_retries = 3)
{
$attempt = 0;
$timeout = 10; // seconds
$connect_timeout = 5; // seconds
$debug = Nuh::$options['d'] ?? 0;
$proxy = Nuh::$options['p'] ?? 0;
while ($attempt < $max_retries) {
if ($proxy) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, Nuh::$options['proxy']);
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
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
if (isset($_config['post'])) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $_config['post']);
} else {
curl_setopt($ch, CURLOPT_POSTFIELDS, ['url' => $url]);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Proxy-Auth: AIkcoRnipSgMK88WMQhOQQN3LKDrNDCIebNfPnEayJdmDeTigx',
]);
} else {
$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
curl_setopt($ch, CURLOPT_FAILONERROR, true);
// POST
if (isset($_config['post'])) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($_config['post']));
}
// JSON
if (isset($_config['header'])) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $_config['header']);
}
}
$response = curl_exec($ch);
if ($response === false) {
$attempt++;
$curl_errorno = curl_errno($ch);
if ($debug && $curl_errorno) {
Notice::note('curl_errorno: '.self::curlerrorcode($curl_errorno));
}
if ($debug) {
echo "Attempt $attempt failed. Retrying...\n";
}
sleep(2); // Optional: Sleep between retries
} else {
curl_close($ch);
return $response;
}
}
echo "All attempts failed.\n";
curl_close($ch);
return null; // Return null if all retries fail
}
public static function curlerrorcode($id)
{
$error_codes = [