Advertisement
Guest User

Untitled

a guest
Mar 18th, 2025
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | Fixit | 0 0
  1. <?php
  2. ob_start();
  3.  
  4. // Database credentials
  5. $host = 'localhost';
  6. $user = ''; // your DB username
  7. $pass = ''; // your DB password
  8. $db = ''; // your database name
  9.  
  10. $conn = new mysqli($host, $user, $pass, $db);
  11.  
  12. if ($conn->connect_error) {
  13. http_response_code(500);
  14. echo "Database connection failed: " . $conn->connect_error . "\n";
  15. ob_end_flush();
  16. exit;
  17. }
  18.  
  19. echo "Apache is up and running.\n";
  20.  
  21. $query = "SELECT 1 FROM DUAL";
  22. $result = $conn->query($query);
  23. if ($result) {
  24. echo "Database is up and running.\n";
  25. $result->free();
  26. } else {
  27. http_response_code(500);
  28. echo "Error executing query: " . $conn->error . "\n";
  29. }
  30.  
  31. $query = "SHOW GLOBAL STATUS LIKE 'Uptime'";
  32. $result = $conn->query($query);
  33. if ($result) {
  34. $row = $result->fetch_assoc();
  35. $uptime_seconds = (int)$row['Value'];
  36.  
  37. $days = floor($uptime_seconds / 86400);
  38. $hours = floor(($uptime_seconds % 86400) / 3600);
  39. $minutes = floor(($uptime_seconds % 3600) / 60);
  40. $seconds = $uptime_seconds % 60;
  41.  
  42. echo "MySQL Uptime: {$days} days, {$hours} hours, {$minutes} minutes, {$seconds} seconds\n";
  43.  
  44. if ($uptime_seconds < 86400) {
  45. echo "Warning: MySQL uptime is less than 1 day!\n";
  46. }
  47.  
  48. $result->free();
  49. } else {
  50. echo "Error retrieving MySQL uptime: " . $conn->error . "\n";
  51. }
  52.  
  53. echo "Server Time: " . date('Y-m-d H:i:s') . "\n";
  54.  
  55. $conn->close();
  56. ob_end_flush();
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement