How to protect a script execution on WordPress?

One approach (avoiding PHP timeouts) for a local Linux Cron Job (for exact timing) is creating a WP-CLI command (does not run in the browser), like:

<?php /* Plugin Name: WP-CLI Foo */

function foo_command( $args ) {
    // Adjust to your needs ...
    WP_CLI::success( $args[0] );
}

WP_CLI::add_command( 'foo', 'foo_command' );

and the corresponding command line might be like:

wp --path=/full/path/to/wp-config.php foo bar

where foo is the command and bar is the argument.

One can also use WordPress’ own Cron API and there are ways to sync it with an external cron job via url, if precice run times are needed.

There’s also the cron command of WP-CLI.