views:

387

answers:

4

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?

+1  A: 

add a user

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

i should clarify that the cron job *does* run, it just eventually times out. but i will try this. thank you.
Kyle
also, is it mailing root with any errors?
@tristan nope - running with root prefixing /usr/bin/curl actually threw the only errors i've seen so far
Kyle
what were the errors when you have root in there? it's probably silently erroring otherwise. make sure that if you're assuming any variables that you explicitly declare them (either via the script or in the top of the crontab) also, are you quoting the URL? cron is probably vomiting on the special characters ;) try this: 02 * * * * root /usr/bin/curl --basic --user 'user:pass' "localhost/not/porn" > /var/www/app/filethatrootcanwriteto.log if that fails, try calling it with backticks?
A: 

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.

Phil Carter
thanks - already checked and double checked on that. the script does *not* time out when invoked manually, only when cron is responsible for invoking.
Kyle
+1  A: 

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!

Kyle
A: 

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