fix curl instead of HttpClient to fix server fails
parent
f171441b60
commit
a042fbf560
|
@ -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 {
|
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->setUserAgent('Dotclear.watch ' . My::id() . '/' . self::DISTANT_API_VERSION);
|
||||||
$client->useGzip(false);
|
$client->useGzip(false);
|
||||||
$client->setPersistReferers(false);
|
$client->setPersistReferers(false);
|
||||||
$client->post($path, ['key' => self::key(), 'report' => $contents]);
|
$client->post($path, ['key' => self::key(), 'report' => $contents]);
|
||||||
|
|
||||||
$status = $client->getStatus();
|
$status = (int) $client->getStatus();
|
||||||
$response = $client->getContent();
|
$response = $client->getContent();
|
||||||
unset($client);
|
}
|
||||||
if ($status != 202) {
|
|
||||||
self::error((string) '(' . $status . ') ' . $response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
unset($client);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
unset($client);
|
unset($client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($status == 202) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($status !== false) {
|
||||||
|
self::error((string) '(' . $status . ') ' . $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($force) {
|
if ($force) {
|
||||||
|
|
Loading…
Reference in New Issue