In what scenarios is running PHP scripts in CLI mode preferable to running them through a web server?

Running PHP scripts in CLI mode is preferable when you need to execute scripts without the limitations of a web server, such as longer execution times or memory limits. CLI mode is also useful for running scripts as scheduled tasks or cron jobs. Additionally, CLI mode allows for easier debugging and testing of scripts.

<?php
// Sample PHP script to be run in CLI mode
echo "Hello, World!";