100 lines
3.8 KiB
PHP
100 lines
3.8 KiB
PHP
<?php
|
|
/**
|
|
* Test directo de la API get_menus.php con diagnóstico
|
|
*/
|
|
|
|
echo "<!DOCTYPE html><html><head><title>Test Diagnóstico Menús</title>";
|
|
echo "<style>body{font-family:monospace;padding:20px;} .success{color:green;} .error{color:red;} .info{color:blue;} pre{background:#f0f0f0;padding:10px;border:1px solid #ccc;}</style></head><body>";
|
|
|
|
echo "<h1>🔧 Test Diagnóstico Get Menús API</h1>";
|
|
|
|
try {
|
|
echo "<h2>📞 Llamada directa a get_menus.php</h2>";
|
|
|
|
// Hacer llamada a la API
|
|
$url = 'http://localhost:8000/api/get_menus.php';
|
|
|
|
echo "<p><strong>URL:</strong> $url</p>";
|
|
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_HEADER, 1);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
|
curl_setopt($ch, CURLOPT_COOKIEFILE, ''); // Enable cookies
|
|
|
|
// Agregar cookie de sesión si existe
|
|
if (isset($_COOKIE['PHPSESSID'])) {
|
|
curl_setopt($ch, CURLOPT_COOKIE, 'PHPSESSID=' . $_COOKIE['PHPSESSID']);
|
|
}
|
|
|
|
$response = curl_exec($ch);
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
|
curl_close($ch);
|
|
|
|
$headers = substr($response, 0, $headerSize);
|
|
$body = substr($response, $headerSize);
|
|
|
|
echo "<h3>🔍 Resultado de la llamada</h3>";
|
|
echo "<p><strong>HTTP Code:</strong> $httpCode</p>";
|
|
|
|
echo "<h4>Headers:</h4>";
|
|
echo "<pre>" . htmlspecialchars($headers) . "</pre>";
|
|
|
|
echo "<h4>Body Response:</h4>";
|
|
echo "<pre>" . htmlspecialchars($body) . "</pre>";
|
|
|
|
// Intentar decodificar JSON
|
|
if ($body) {
|
|
$jsonData = json_decode($body, true);
|
|
if ($jsonData !== null) {
|
|
echo "<h4>📋 JSON Decodificado:</h4>";
|
|
echo "<pre>" . json_encode($jsonData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "</pre>";
|
|
|
|
if (isset($jsonData['success'])) {
|
|
if ($jsonData['success']) {
|
|
echo "<div class='success'>✅ API respondió exitosamente</div>";
|
|
if (isset($jsonData['data'])) {
|
|
echo "<p><strong>Menús encontrados:</strong> " . count($jsonData['data']) . "</p>";
|
|
}
|
|
} else {
|
|
echo "<div class='error'>❌ API reportó error: " . ($jsonData['error'] ?? 'Error desconocido') . "</div>";
|
|
if (isset($jsonData['debug'])) {
|
|
echo "<p><strong>Debug info:</strong> " . $jsonData['debug'] . "</p>";
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
echo "<div class='error'>❌ Respuesta no es JSON válido</div>";
|
|
}
|
|
}
|
|
|
|
// Mostrar logs si existen
|
|
echo "<h3>📋 Logs del Sistema</h3>";
|
|
$logFile = dirname(__DIR__) . '/logs/system.log';
|
|
if (file_exists($logFile)) {
|
|
$logs = file_get_contents($logFile);
|
|
$recentLogs = array_slice(explode("\n", $logs), -20); // Últimas 20 líneas
|
|
echo "<h4>Últimas 20 líneas del log:</h4>";
|
|
echo "<pre>" . htmlspecialchars(implode("\n", $recentLogs)) . "</pre>";
|
|
} else {
|
|
echo "<p>No se encontró archivo de log en: $logFile</p>";
|
|
}
|
|
|
|
// Mostrar error log de PHP si existe
|
|
$errorLogFile = dirname(__DIR__) . '/logs/error.log';
|
|
if (file_exists($errorLogFile)) {
|
|
$errorLogs = file_get_contents($errorLogFile);
|
|
$recentErrorLogs = array_slice(explode("\n", $errorLogs), -10); // Últimas 10 líneas
|
|
echo "<h4>Últimas 10 líneas del error log:</h4>";
|
|
echo "<pre>" . htmlspecialchars(implode("\n", $recentErrorLogs)) . "</pre>";
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
echo "<div class='error'>❌ Error en test: " . $e->getMessage() . "</div>";
|
|
}
|
|
|
|
echo "<hr><p><small>Test ejecutado: " . date('Y-m-d H:i:s') . "</small></p>";
|
|
echo "</body></html>";
|
|
?>
|