tags:

views:

60

answers:

1

Hi guys, I'm experiencing some problems with ob_* function when it runs as a cronjob:

<?php
function getLayout($file, $extract=array()) {

    if (is_file($file)) {

     if (count($extract) > 0) {
      extract($extract);
     }

     ob_start();
     include $file;
     $contents = ob_get_contents();
     ob_end_clean();

     return $contents;
    }

    return false;
}

file_put_contents('somecachefile.html', getLayout('somefile.php', array('var1'=>$val1, 'var2'=>$val2)));
?>

The cronjob is setup like this: (runs every minute)

* * * * * /usr/bin/php /path/to/cron.php > /dev/null

In this case nothing happen but the cron really ran.

If i call this (/usr/bin/php /path/to/cron.php) from the command line everything is working as expected.

Any ideas where i make a mistake???

Thanks for the help upfront!

+5  A: 

You probably need to use an absolute path on 'somefile.php'. It is probably getting created in the pwd of cron. Or you could do a chdir at the beginning of the script of in the cron statement.

Swish
Thanks Swish!The problem was the paths to the files. Using the absolute paths help in my case.Thanks again!
plamen