Tutorial :cron job seems to be timing out



Question:

Have the following cronjob set up in root's crontab: (centos 5.x)

2 * * * * /usr/bin/curl --basic --user 'user:pass' http://localhost/cron/do_some_action > /var/www/app/cronlog.log  

Invoking the actual command works as expected, however when the cronjob runs, it always times out. I've used set_time_limit() and related php.ini settings to ensure it's not PHP dying, and /var/log/cron looks normal to me:

Jun 4 10:02:01 foobar crond[12138]: (root) CMD ([snip])

Any ideas about why the cronjob would be dying?


Solution:1

add a user

02 * * * * root /usr/bin/curl --basic --user 'user:pass' http://localhost/not/porn > /var/www/app/filethatrootcanwriteto.log


Solution:2

I figured it out - curl's progress stats:

(100 65622    0 65622    0     0   1039      0 --:--:--  0:01:03 --:--:--  1927)  

were being written to stderr for some reason - adding 2>&1 at the end of the command fixed it:

2 * * * * /usr/bin/curl --basic --user 'user:pass' http://localhost/cron/do_some_action > /var/www/app/cronlog.log 2>&1  

Thanks to everyone for all the insight!


Solution:3

There can be 2 php.ini files, one for apache and one for CLI.

locate php.ini should find both, I'd suggest you check there first.


Solution:4

This can also be avoided by buffering your PHP output using ob_start() and ob_end_flush() to prevent curl from returning status prematurely.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »