Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 2 min read

How to Monitor Your CodeIgniter Application with Vigilmon

How to Monitor Your CodeIgniter Application with Vigilmon CodeIgniter is a lightweight PHP framework favored for its simplicity and small footprint. Despite being "the MVC framework for people who hate MVC frameworks,"

How to Monitor Your CodeIgniter Application with Vigilmon

CodeIgniter is a lightweight PHP framework favored for its simplicity and small footprint. Despite being "the MVC framework for people who hate MVC frameworks," CodeIgniter powers thousands of production applications worldwide β€” many of them without any uptime monitoring.

This guide walks through adding robust monitoring to your CodeIgniter application with Vigilmon.

Why Monitor CodeIgniter Apps?

CodeIgniter apps are often deployed on shared hosting or VPS environments where:

  • PHP timeouts fail silently
  • Database connections can drop without alerting anyone
  • Cron jobs stop running without notice
  • Memory limits cause quiet crashes

Vigilmon monitors your endpoints every minute (or every 30 seconds on paid plans) and alerts you immediately when something breaks.

Step 1: Create a Health Check Controller

<?php
// application/controllers/Health.php

defined('BASEPATH') OR exit('No direct script access allowed');

class Health extends CI_Controller
{
    public function index()
    {
        $this->output
            ->set_content_type('application/json')
            ->set_output(json_encode([
                'status' => 'ok',
                'timestamp' => time(),
                'version' => CI_VERSION,
            ]));
    }

    public function deep()
    {
        $status = 'ok';
        $checks = [];

        // Check database
        try {
            $this->load->database();
            $this->db->query('SELECT 1');
            $checks['database'] = 'ok';
        } catch (Exception $e) {
            $checks['database'] = 'error';
            $status = 'degraded';
        }

        http_response_code($status === 'ok' ? 200 : 503);

        $this->output
            ->set_content_type('application/json')
            ->set_output(json_encode([
                'status' => $status,
                'checks' => $checks,
                'timestamp' => time(),
            ]));
    }
}

Step 2: Configure Routes

// application/config/routes.php
$route['health'] = 'health/index';
$route['health/deep'] = 'health/deep';

Step 3: Register in Vigilmon

  1. Go to vigilmon.online and sign in
  2. Click Add Monitor β†’ HTTP/HTTPS Monitor
  3. URL: https://yourapp.com/health
  4. Method: GET
  5. Expected status: 200
  6. Check interval: 60 seconds
  7. Alert channels: email, Slack, or webhook

Step 4: Monitor CodeIgniter Cron Jobs

CodeIgniter applications often rely heavily on scheduled tasks. Use Vigilmon heartbeat monitors:

<?php
// application/controllers/cli/Sync.php (CLI controller)

defined('BASEPATH') OR exit('No direct script access allowed');

class Sync extends CI_Controller
{
    public function run()
    {
        // ... do your sync job ...

        // Ping Vigilmon heartbeat to confirm job ran
        $ch = curl_init('https://hb.vigilmon.online/your-heartbeat-id');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_exec($ch);
        curl_close($ch);

        echo 'Sync complete' . PHP_EOL;
    }
}
# crontab -e
*/15 * * * * php /var/www/html/index.php cli/sync/run

If the cron job stops running, Vigilmon's heartbeat monitor alerts you within the configured window.

Monitoring Checklist for CodeIgniter

Monitor Type Endpoint/Config Purpose
HTTP Monitor /health App availability
HTTP Monitor /health/deep App + DB connectivity
Heartbeat Vigilmon heartbeat URL Cron job liveness
Keyword Monitor Your homepage Detect content failures

Conclusion

CodeIgniter's simplicity makes it fast to add monitoring. With Vigilmon, you get instant alerts, a public status page, and full response time tracking β€” all without managing infrastructure.

Monitor your CodeIgniter app for free at vigilmon.online

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.