Skip to main content
GET
/
api
/
health.php
Health Check
curl --request GET \
  --url https://api.example.com/api/health.php
{
  "status": "<string>",
  "timestamp": "<string>",
  "checks": {
    "database": {
      "status": "<string>",
      "latency_ms": 123,
      "error": "<string>"
    },
    "openai": {
      "status": "<string>",
      "message": "<string>",
      "error": "<string>"
    },
    "active_conversations": 123,
    "disk": {
      "free_gb": 123,
      "usage_percent": 123,
      "status": "<string>"
    },
    "memory": {
      "usage_mb": 123,
      "peak_mb": 123
    }
  }
}

Overview

The health check endpoint provides comprehensive system status information, including database connectivity, OpenAI service status, active conversations, disk usage, and memory consumption.

Endpoint

GET /api/health.php

Response

status
string
required
Overall system health status
  • healthy: All systems operational
  • unhealthy: One or more critical systems down
timestamp
string
required
ISO 8601 timestamp of the health check
checks
object
required
Detailed health check results for each subsystem
database
object
Database connectivity status
status
string
up or down
latency_ms
number
Database query latency in milliseconds
error
string
Error message if database is down
openai
object
OpenAI service status
status
string
Service status: operational, degraded, or unknown
message
string
Status message (e.g., “Insufficient funds”, “OK”)
error
string
Error message if status check failed
active_conversations
number
Count of active conversations in the system
disk
object
Disk usage information
free_gb
number
Free disk space in gigabytes
usage_percent
number
Disk usage percentage
status
string
critical if usage > 90%, otherwise ok
memory
object
Memory usage information
usage_mb
number
Current memory usage in megabytes
peak_mb
number
Peak memory usage in megabytes

Status Codes

  • 200 OK: System is healthy
  • 503 Service Unavailable: System is unhealthy (one or more checks failed)

Example Response

{
  "status": "healthy",
  "timestamp": "2024-03-06T10:30:00+00:00",
  "checks": {
    "database": {
      "status": "up",
      "latency_ms": 0
    },
    "openai": {
      "status": "operational",
      "message": "OK"
    },
    "active_conversations": 42,
    "disk": {
      "free_gb": 125.43,
      "usage_percent": 35.67,
      "status": "ok"
    },
    "memory": {
      "usage_mb": 24.5,
      "peak_mb": 28.3
    }
  }
}

Implementation Details

The health check performs the following operations:
  1. Database Check: Executes SELECT 1 to verify connectivity
  2. OpenAI Status: Retrieves openai_status from settings table
  3. Active Conversations: Counts conversations with status = "active"
  4. Disk Usage: Checks available disk space and calculates usage percentage
  5. Memory Usage: Reports current and peak PHP memory consumption

Use Cases

  • Monitoring: Integrate with monitoring tools (Prometheus, Datadog, etc.)
  • Load Balancers: Configure health checks for automated failover
  • Alerting: Trigger alerts when system becomes unhealthy
  • Status Pages: Display real-time system status to users

Build docs developers (and LLMs) love