Question

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 made a mistake?

Thanks for the help upfront!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top