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); self::write($contents);
$client = false;
$status = 500; $status = 500;
$response = ''; $response = '';
$url = sprintf(self::url(), 'report'); $url = sprintf(self::url(), 'report');
$path = '';
if ($client = HttpClient::initClient($url, $path)) {
try {
$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(); try {
$response = $client->getContent(); if (function_exists('curl_init')) {
unset($client); if (false !== ($client = curl_init($url))) {
if ($status != 202) { curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
self::error((string) '(' . $status . ') ' . $response); 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]);
return; $status = (int) $client->getStatus();
} catch (Exception $e) { $response = $client->getContent();
unset($client); }
} }
unset($client);
} catch (Exception $e) {
unset($client);
}
if ($status == 202) {
return;
}
if ($status !== false) {
self::error((string) '(' . $status . ') ' . $response);
} }
if ($force) { if ($force) {