File size: 1,764 Bytes
2da3758
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
// Health Check Endpoint for Render.com
// This keeps the service active by preventing sleep mode

header('Content-Type: application/json');
header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');

// Basic health check
$health = [
    'status' => 'healthy',
    'timestamp' => date('c'),
    'service' => 'SoftEdge Corporation Website',
    'version' => '2.0.0',
    'uptime' => time() - ($_SERVER['REQUEST_TIME'] ?? time()),
    'checks' => [
        'database' => 'not_required',
        'filesystem' => is_writable(__DIR__) ? 'writable' : 'read_only',
        'php' => PHP_VERSION,
        'memory' => memory_get_peak_usage(true) . ' bytes',
        'server' => $_SERVER['SERVER_SOFTWARE'] ?? 'unknown'
    ]
];

// Check if critical files exist
$criticalFiles = [
    'index.php',
    'composer.json',
    'vendor/autoload.php',
    'assets/logo.jpeg'
];

foreach ($criticalFiles as $file) {
    if (!file_exists(__DIR__ . '/' . $file)) {
        $health['status'] = 'degraded';
        $health['checks']['missing_files'][] = $file;
    }
}

// Check if email service is configured
$emailConfigured = false;
if (file_exists(__DIR__ . '/.env')) {
    $envContent = file_get_contents(__DIR__ . '/.env');
    $emailConfigured = strpos($envContent, 'SMTP_HOST=') !== false;
}
$health['checks']['email_configured'] = $emailConfigured;

// Return appropriate HTTP status
if ($health['status'] === 'healthy') {
    http_response_code(200);
} elseif ($health['status'] === 'degraded') {
    http_response_code(200); // Still return 200 for uptime monitors
} else {
    http_response_code(503);
}

echo json_encode($health, JSON_PRETTY_PRINT);
?>