fix curl instead of HttpClient to fix server fails

master
Jean-Christian Paul Denis 2023-08-09 00:03:12 +02:00
parent f171441b60
commit a042fbf560
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
1 changed files with 33 additions and 15 deletions

View File

@ -188,28 +188,46 @@ class Utils
self::write($contents);
$client = false;
$status = 500;
$response = '';
$url = sprintf(self::url(), 'report');
$path = '';
if ($client = HttpClient::initClient($url, $path)) {
try {
if (function_exists('curl_init')) {
if (false !== ($client = curl_init($url))) {
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
curl_setopt($client, CURLOPT_POST, true);
curl_setopt($client, CURLOPT_POSTFIELDS, ['key' => self::key(), 'report' => $contents]);
if (false !== ($response = curl_exec($client))) {
$status = (int) curl_getinfo($client, CURLINFO_HTTP_CODE);
}
}
} else {
$path = '';
if (false !== ($client = HttpClient::initClient($url, $path))) {
$client->setUserAgent('Dotclear.watch ' . My::id() . '/' . self::DISTANT_API_VERSION);
$client->useGzip(false);
$client->setPersistReferers(false);
$client->post($path, ['key' => self::key(), 'report' => $contents]);
$status = $client->getStatus();
$status = (int) $client->getStatus();
$response = $client->getContent();
unset($client);
if ($status != 202) {
self::error((string) '(' . $status . ') ' . $response);
}
}
return;
unset($client);
} catch (Exception $e) {
unset($client);
}
if ($status == 202) {
return;
}
if ($status !== false) {
self::error((string) '(' . $status . ') ' . $response);
}
if ($force) {