You saved me a lot of time.

I also had a case where i wanted to check if the script is accessed via cron or directly to do something different later.

I did id like this (maybe not the most elegant way, but useful for somebody) :

// Check if accesses by cron
$accessPath = getcwd();
$realPath = chdir( __DIR__ );
$realPath = getcwd();
if ($accessPath != $realPath){
$cron = 1;
} else {
$cron = 0;
}

CAPTCHA