| Current Path : /home/ataenra/www/ATA/INTRANET/Admin/Gestion_ACC/ |
| Current File : /home/ataenra/www/ATA/INTRANET/Admin/Gestion_ACC/testconnection.php |
<?php
// Désactiver l'affichage des erreurs en production
error_reporting(E_ALL);
ini_set('display_errors', 1);
// URL de test PVGIS avec tous les paramètres requis
$testUrl = 'https://re.jrc.ec.europa.eu/api/v5_2/PVcalc?' . http_build_query([
'lat' => 48.8566,
'lon' => 2.3522,
'peakpower' => 1,
'loss' => 14,
'angle' => 35,
'aspect' => 0,
'outputformat' => 'json',
]);
// Test avec PHP curl
function testCurlConnection() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $GLOBALS['testUrl']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); // Ajout d'un User-Agent
$response = curl_exec($ch);
$error = curl_error($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return [
'success' => !empty($response),
'error' => $error,
'http_code' => $info['http_code'],
'response' => $response
];
}
// Test avec file_get_contents
function testFileGetContents() {
$ctx = stream_context_create([
'http' => [
'timeout' => 5,
'user_agent' => 'Mozilla/5.0' // Ajout d'un User-Agent
]
]);
try {
$response = file_get_contents($GLOBALS['testUrl'], false, $ctx);
return [
'success' => !empty($response),
'error' => error_get_last(),
'response' => $response
];
} catch (Exception $e) {
return [
'success' => false,
'error' => $e->getMessage(),
'response' => null
];
}
}
// Exécuter les tests
$curlTest = testCurlConnection();
$fileGetContentsTest = testFileGetContents();
// Afficher les résultats
header('Content-Type: application/json');
echo json_encode([
'curl_test' => $curlTest,
'file_get_contents_test' => $fileGetContentsTest,
'php_version' => PHP_VERSION,
'allow_url_fopen' => ini_get('allow_url_fopen'),
'curl_enabled' => function_exists('curl_version'),
'server_software' => $_SERVER['SERVER_SOFTWARE'] ?? 'Unknown'
], JSON_PRETTY_PRINT);