
PHP powers a significant share of the web — from WordPress and Drupal sites to custom applications built with Laravel, Symfony, and CodeIgniter. While PHP itself is stable, PHP applications can fail in ways that are specific to the language and runtime. This guide covers monitoring PHP applications for uptime and availability.
Understanding failure modes helps you monitor the right things:
memory_limit exceededExternal HTTP monitoring catches most of these — a 500 error or blank page indicates the application is failing, regardless of the specific PHP-level cause.
<?php
// health.php
header('Content-Type: application/json');
$health = ['status' => 'ok'];
$status_code = 200;
// Test database connection
try {
$pdo = new PDO(
'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME,
DB_USER,
DB_PASS,
[PDO::ATTR_TIMEOUT => 3]
);
$pdo->query('SELECT 1');
$health['database'] = 'ok';
} catch (PDOException $e) {
$health['database'] = 'error';
$health['status'] = 'degraded';
$status_code = 503;
}
http_response_code($status_code);
echo json_encode($health);
// routes/web.php
Route::get('/health', function () {
$status = ['status' => 'ok'];
$code = 200;
try {
DB::connection()->getPdo();
$status['database'] = 'ok';
} catch (Exception $e) {
$status['database'] = 'error';
$status['status'] = 'degraded';
$code = 503;
}
return response()->json($status, $code);
});
// Add to your theme's functions.php or a custom plugin
add_action('rest_api_init', function() {
register_rest_route('health/v1', '/status', [
'methods' => 'GET',
'callback' => function() {
global $wpdb;
$db_ok = ($wpdb->get_var("SELECT 1") === '1');
return rest_ensure_response([
'status' => $db_ok ? 'ok' : 'degraded',
'database' => $db_ok ? 'ok' : 'error'
]);
},
'permission_callback' => '__return_true'
]);
});
// Access at: /wp-json/health/v1/status
Configure your uptime monitor to check your health endpoint:
Monitor: https://yourdomain.com/health
Expected status: 200
Content check: "ok"
Interval: 1 minute
Also monitor your main application URL with content verification:
Monitor: https://yourdomain.com
Expected status: 200
Content check: your page title or brand name
Content verification catches PHP errors that return 200 status but display error pages — common with custom error handling or error_reporting set to display errors.
If you use Nginx + PHP-FPM (the most common production setup), monitor PHP-FPM's status endpoint:
# In your Nginx config
location /php-fpm-status {
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
allow 127.0.0.1;
deny all;
}
Check PHP-FPM status locally: curl http://localhost/php-fpm-status
This shows active workers, idle workers, and queue length — useful for detecting PHP-FPM pool exhaustion.
After deploying new PHP code, you may need to clear the OPcache to ensure new code is served:
# Via PHP CLI
php -r "opcache_reset();"
# Or via a deployment script
curl https://yourdomain.com/opcache-reset.php
Failure to clear OPcache after deployment means old code continues to run — which can cause application errors if the database schema changed.
For WordPress sites, monitor:
Monitor: https://yourwordpresssite.com
Content check: your site name or a stable HTML element
Monitor: https://yourwordpresssite.com/wp-login.php
Expected status: 200
Content check: "Log In"
The wp-login.php check verifies WordPress is functioning. Also set up:
Configure appropriate alerts for PHP application severity:
| Failure | Alert |
|---|---|
| Site returning 500 errors | SMS + Slack |
| Response time > 5 seconds | Slack |
| SSL certificate expiry | Email (30 days) |
| Domain expiry | Email (60 days) |
See how to set up downtime alerts for full configuration.
Monitoring can help you catch deployment-related PHP failures:
Monitor your PHP applications externally at Domain Monitor — detect failures before your users do.
A subdomain takeover lets an attacker claim your subdomain by exploiting dangling DNS records. Learn how it happens, real-world examples, and how DNS monitoring detects it.
Read moreMean time to detect (MTTD) measures how long it takes to discover an incident after it starts. Reducing MTTD is one of the highest-leverage improvements in reliability engineering.
Read moreBlack box monitoring tests your systems from the outside, the way users experience them — without access to internal code or infrastructure. Learn how it works and when to use it.
Read moreLooking to monitor your website and domains? Join our platform and start today.