Debug Mode (PHP, Errors, and Database Logs)

Debug Mode (PHP, Errors, and Database Logs)

Enabling debug mode in Osclass helps administrators and developers diagnose issues related to PHP errors, database queries, and cache performance. Debug logs provide valuable insights that can assist in troubleshooting and optimizing performance. However, it is strongly recommended to disable debugging on production websites.

PHP Debug Mode

If your website displays an "Error 500" page, it likely means PHP errors are occurring in the background but are not visible. To enable debugging and view these errors, you need to modify the config.php file in the root directory of your Osclass installation.

Enable PHP Error Logging

Add the following lines to enable PHP error display and logging:

ini_set('display_errors', 'on');
ini_set('log_errors', 'on');
ini_set('display_startup_errors', 'on');
ini_set('error_reporting', E_ALL);

Enable Osclass Debug Mode

To enable Osclass-specific debugging, add:

define('OSC_DEBUG', true);

This will display PHP errors, notices, and warnings directly on your website.

Save Error Logs to a File

To store error logs in a file instead of displaying them publicly, enable logging by adding:

define('OSC_DEBUG_LOG', true);

This will save error logs to the oc-content/debug.log file.

Additional Debugging Options

Osclass provides additional debugging options for specific components:

  • Debug Osclass cache mechanisms (Memcache, Redis, APC, etc.):
define('OSC_DEBUG_CACHE', true);
  • Debug PHP mailer (useful for troubleshooting email sending issues):
define('PHPMAILER_DEBUG_LEVEL', 2);

Accepted debug levels:

  • 1 – Client only
  • 2 – Client and server (default)
  • 3 – Client, server, and connection
  • 4 – Low-level information

Database Debug Mode

Database debugging in Osclass helps track database queries and performance. Enabling this mode may significantly affect performance, so it should only be used in development environments.

Enable Database Query Logging

Add the following lines to config.php to log database queries:

define('OSC_DEBUG_DB', true);

This will store all SQL queries in an array and display them at the bottom of the page.

Save Database Queries to a Log File

To save database logs into a file, add:

define('OSC_DEBUG_DB_LOG', true);

The log file queries.log will be created in the oc-content folder. If your Apache server lacks write permissions, you may need to create the file manually and set the appropriate permissions (e.g., chmod 666 queries.log).

Analyze Query Performance

To run EXPLAIN queries and log their results, use:

define('OSC_DEBUG_DB_EXPLAIN', true);

This will save detailed query execution plans to explain_queries.log in oc-content. This setting is useful for optimizing slow queries.

Debug Log in Backoffice

Osclass provides a built-in debug log viewer in the backoffice. To access it, navigate to Tools > Debug/Error Log in the left sidebar. The left panel displays whether debug modes are enabled and provides instructions for enabling error logs. The right panel shows the contents of the debug.log file, which stores PHP error logs when OSC_DEBUG_LOG is enabled in config.php.

Backoffice debug log
Backoffice debug log

Important Considerations

  • Always disable debug logging on production websites.
  • Use OSC_DEBUG_LOG to store errors instead of displaying them.
  • Database debugging (OSC_DEBUG_DB) can significantly slow down your website.
  • For best performance, use debugging only when troubleshooting specific issues.

By enabling and configuring these debug settings, you can efficiently diagnose and resolve issues in Osclass.