Are there any best practices or guidelines for ensuring PHP scripts work consistently across different access methods?

When developing PHP scripts, it's important to ensure that they work consistently across different access methods, such as command line, web server, or cron jobs. One way to achieve this is by setting up a configuration file that contains environment-specific settings and variables. By including this configuration file at the beginning of your PHP scripts, you can ensure that the script behaves consistently regardless of how it is accessed.

// config.php
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', 'password');
define('DB_NAME', 'database');

// script.php
require_once 'config.php';

// Your PHP script code here