1

I'm using Laravel 4 to build my site, and I just created a new command that backs up my database and does a few database updates. Calling it on my computer through windows command prompt works fine:

php artisan dbupdate

But when I try to use it as a cron job on my shared host server like this:

1 * * * * php -q /home/******/laravel/artisan dbupdate

I get the following error:

Failed to start the session because headers have already been sent by "" at line 0.

I thought it might be something in my code, so I commented it all out and just put a echo "hello command" line in to test it, but I still got the same error. It's coming from laravel/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

I'm pretty new to Laravel and quite new to cron jobs. What could be the problem?

reikyoushin
  • 1,993
  • 2
  • 24
  • 40
Chris
  • 4,277
  • 7
  • 40
  • 55
  • 1
    possible duplicate of [Launching Laravel 4 artisan command through Cron task](http://stackoverflow.com/questions/17064347/launching-laravel-4-artisan-command-through-cron-task) – reikyoushin Sep 24 '13 at 13:24
  • I do believe you're right. I never saw that post while searching for an answer. Thanks, it helped me understand why I need to use php-cli – Chris Sep 26 '13 at 07:16

2 Answers2

2

I tried using php-cli instead of php as in this post

So my cron job now looks like this:

1 * * * * php-cli -q /home/******/laravel/artisan dbupdate

And though I still don't quite understand what's different about this, it works perfectly.

Chris
  • 4,277
  • 7
  • 40
  • 55
0

In short you'll be attempting to send a header after having already sent some output. I can't tell from what you've put but it's likely that somewhere in the code you have an include() function.

For a full explanation of the causes and fixes look here - https://stackoverflow.com/a/8028987/1566393

Community
  • 1
  • 1
NickW
  • 141
  • 1
  • 6
  • Yeah, that's what I assumed as well, but even when I took everything out of my command for testing, it still threw the same error. It confused me because it seems to work for other laravel users this way. Anyway, I found an answer that works using php-cli, though I don't quite understand it... – Chris Sep 23 '13 at 22:51