I have created a cron job at my webserver. That cron runs a php file every few hours. It’s cache creating technique. But there’s a problem – my cron command looks like this: php -q /folder/phpfile.php . When i run “phpfile.php” directly from my browser, everything is ok, but when CRON runs that file, it ALWAYS outputs “headers already sent” error to “error_log”! Mentioned php file DO begins with if(!isset($_SESSION)) session_start(); but “error_log” show that exactly “session_start()” line is throwing the warning!
What’s wrong? Why is everything ok when i run that file with browser, but when cron does it, “headers already sent” is generated?
Reason why it works in browser is probably because you have different php.ini settings for your web server and for cli-php.
output_buffering directive is apperantly ON in your web-server and turned off in cli-php and it is right thing. Because no one wants to wait for content till script ends a job. We want to see what is happening when script is running.
Wrong thing is that you send header with a cli script. Session is not really need in terminal, is it?