Reputation: 43
I have a php script which runs fine direct from a web page that checks the last modified time of all html files for a site map, However when i run it as a cron job if errors out.
Below is the script, the cron job and the error.
$path = "/home/mydir/";
// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
// Loop through the files
while ($file = readdir($dir_handle)) {
if($file == "." || $file == ".." || $file == "index.php" )
continue;
if(strpos($file, ".html") !== false) {
$a=filemtime($file);
}
}
}
php /home/mydir/pdate.php /dev/null && echo "Site Map completed "$(date) >>/var/log/cron.log
Error PHP Warning: filemtime(): stat failed
Any ideas on what i should change for this one please?
Upvotes: 0
Views: 217
Reputation: 70540
You are in another directory. Either:
chdir($path);
Or:
filemtime($path.DIRECTORY_SEPARATOR.$file);
Upvotes: 1