PDA

View Full Version : Cron PHP Script - Read file problems



grim
07-12-2004, 08:49 AM
Hello,

I have a small script that runs and reads through .php files in a directory and counts the number of files, lines in each file and total file size.

The script runs perfectly from a browser, but scheduled in Cron it does not read the lines or file size (it does count the number of files total).

I'm pretty new to Cron, and I'm not sure how to see any error messages if there are any when the script runs.

Here's a snippet of the PHP code



$mydir = dir('/var/www/html');
while(($file = $mydir->read()) != false)
{
if(substr($file,strrpos($file,".")+1) == "php")
{
$lines = count(file($file));
$totallines += $lines;
$countfile++;
$totalsize += filesize($file);
}
}


This is my cron line:
0 * * * * /bin/php /var/www/html/push.php >/dev/null

I'm assuming this is some sort of permission problem, but I'm just really not sure. Any help would be appreciated.

WestHost - MMellor
07-12-2004, 10:46 AM
Hello Grim,

I believe that you need to use this syntax:

$lines = count(file(${dir}/${file}));

What you need to do is use full paths as references to your files. Just glancing at your code this is what I would guess is the problem that you are having. Keep us posted on your progress with this.

grim
07-12-2004, 11:45 AM
Excellent.

Much thanks Michael, it's working now.