What are some best practices for handling cronjob scripts that need to be checked for existence without executing during user interactions?

When handling cronjob scripts that need to be checked for existence without executing during user interactions, a best practice is to use a conditional check to determine if the script is being executed from the command line interface (CLI) or from a web server request. By checking the PHP_SAPI constant, you can ensure that the script only runs when executed through the CLI and not during user interactions on a web server.

if (PHP_SAPI === 'cli') {
    // Code for cronjob script goes here
    // This code will only execute when the script is run from the command line
}