🚨 Emergency Diagnostic"; echo ""; echo "
PHP Version: " . PHP_VERSION . "
"; echo "
Current Time: " . date('Y-m-d H:i:s') . "
"; echo "
Memory Limit: " . ini_get('memory_limit') . "
"; // Test 1: Check if files exist (don't include them yet) echo "

1. File Existence Check

"; $coreFiles = [ 'includes/config.php', 'includes/db.php', 'includes/GptHelper.php', 'includes/auth.php', 'login.php', 'dashboard.php', 'index.php' ]; foreach ($coreFiles as $file) { if (file_exists($file)) { $size = filesize($file); echo "
✅ $file exists ($size bytes)
"; } else { echo "
❌ $file missing
"; } } // Test 2: Check file contents for syntax errors echo "

2. File Content Check

"; function checkPHPSyntax($file) { if (!file_exists($file)) return "File not found"; $content = file_get_contents($file); // Check for basic PHP syntax if (strpos($content, '&1"); unlink($temp); if ($output && strpos($output, 'No syntax errors') === false) { return "Syntax error: " . trim($output); } return "OK"; } $testFiles = ['includes/config.php', 'includes/db.php', 'includes/GptHelper.php']; foreach ($testFiles as $file) { $result = checkPHPSyntax($file); if ($result === "OK") { echo "
✅ $file syntax OK
"; } else { echo "
❌ $file: $result
"; } } // Test 3: Try including config.php only echo "

3. Config Test

"; try { ob_start(); include 'includes/config.php'; $output = ob_get_clean(); if (defined('DB_HOST')) { echo "
✅ Config loaded successfully
"; echo "
DB_HOST: " . DB_HOST . "
"; echo "
DB_NAME: " . DB_NAME . "
"; } else { echo "
❌ Config loaded but constants not defined
"; } if (!empty($output)) { echo "
❌ Config produced output: " . htmlspecialchars($output) . "
"; } } catch (ParseError $e) { echo "
❌ Config parse error: " . $e->getMessage() . "
"; } catch (Error $e) { echo "
❌ Config fatal error: " . $e->getMessage() . "
"; } catch (Exception $e) { echo "
❌ Config exception: " . $e->getMessage() . "
"; } // Test 4: Try including db.php only echo "

4. Database Class Test

"; try { ob_start(); include 'includes/db.php'; $output = ob_get_clean(); if (class_exists('Database')) { echo "
✅ Database class loaded
"; } else { echo "
❌ Database class not found
"; } if (!empty($output)) { echo "
❌ DB file produced output: " . htmlspecialchars($output) . "
"; } } catch (ParseError $e) { echo "
❌ DB parse error: " . $e->getMessage() . "
"; } catch (Error $e) { echo "
❌ DB fatal error: " . $e->getMessage() . "
"; } catch (Exception $e) { echo "
❌ DB exception: " . $e->getMessage() . "
"; } // Test 5: Try including GptHelper.php only echo "

5. GptHelper Test

"; try { ob_start(); include 'includes/GptHelper.php'; $output = ob_get_clean(); if (class_exists('GptHelper')) { echo "
✅ GptHelper class loaded
"; } else { echo "
❌ GptHelper class not found
"; } if (!empty($output)) { echo "
❌ GptHelper produced output: " . htmlspecialchars($output) . "
"; } } catch (ParseError $e) { echo "
❌ GptHelper parse error: " . $e->getMessage() . "
"; } catch (Error $e) { echo "
❌ GptHelper fatal error: " . $e->getMessage() . "
"; } catch (Exception $e) { echo "
❌ GptHelper exception: " . $e->getMessage() . "
"; } // Test 6: Check error log echo "

6. Recent Error Log

"; $errorLog = ini_get('error_log'); if ($errorLog && file_exists($errorLog)) { $errors = file_get_contents($errorLog); $recentErrors = array_slice(explode("\n", $errors), -10); echo "
Recent errors:
"; echo "
" . htmlspecialchars(implode("\n", $recentErrors)) . "
"; } else { echo "
No error log found at: $errorLog
"; } // Test 7: Check if any processes are stuck echo "

7. Database Connection Test

"; try { if (defined('DB_HOST') && class_exists('Database')) { $db = Database::getInstance(); $result = $db->query("SELECT 1 as test"); if ($result) { echo "
✅ Database connection works
"; // Check optimization state $stateQuery = $db->query("SELECT * FROM optimization_analysis_state LIMIT 1"); if ($stateQuery && $stateQuery->num_rows > 0) { $state = $stateQuery->fetch_assoc(); echo "
Analysis running: " . ($state['is_running'] ? 'YES' : 'NO') . "
"; if ($state['is_running']) { echo "
⚠️ Analysis process is still marked as running - this might be causing issues
"; echo "
🛑 Stop Analysis Process
"; } } } else { echo "
❌ Database query failed
"; } } } catch (Exception $e) { echo "
❌ Database test error: " . $e->getMessage() . "
"; } // Handle stop request if (isset($_GET['stop'])) { try { if (defined('DB_HOST') && class_exists('Database')) { $db = Database::getInstance(); $db->query("UPDATE optimization_analysis_state SET is_running = 0, should_pause = 0"); echo "
✅ Analysis process stopped
"; } } catch (Exception $e) { echo "
❌ Stop failed: " . $e->getMessage() . "
"; } } echo "

✅ Diagnostic Complete

"; echo "
If this page loads, PHP is working. Check the errors above to find the issue.
"; ?>