Can you provide an example of when using a Singleton in PHP is appropriate and beneficial?

Using a Singleton in PHP is appropriate and beneficial when you need to ensure that a class has only one instance throughout the entire application. This can be useful for managing global resources, such as database connections or configuration settings, without the need to create multiple instances and potentially waste resources.

class Database {
    private static $instance;

    private function __construct() {
        // Database connection setup
    }

    public static function getInstance() {
        if (!self::$instance) {
            self::$instance = new Database();
        }
        return self::$instance;
    }

    // Other database methods
}

// Usage
$db = Database::getInstance();