cron 作业似乎超时了
在 root 的 crontab 中设置以下 cronjob:(centos 5.x)
2 * * * * /usr/bin/curl --basic --user 'user:pass' http://localhost/cron/do_some_action > /var/www/app/cronlog.log
调用实际命令按预期工作,但是当 cronjob 运行时,它总是超时。 我使用了 set_time_limit() 和相关的 php.ini 设置来确保 PHP 不会死掉,并且 /var/log/cron 对我来说看起来很正常:
6 月 4 日 10:02:01 foobar crond[12138]: (root) CMD ([snip])
关于为什么 cronjob 会死掉有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我想通了 -curl 的进度统计:
由于某种原因被写入 stderr -在命令末尾添加 2>&1 修复了它:
感谢大家的所有见解!
I figured it out - curl's progress stats:
were being written to stderr for some reason - adding 2>&1 at the end of the command fixed it:
Thanks to everyone for all the insight!
添加用户
02 * * * * root /usr/bin/curl --basic --user 'user:pass' http: //localhost/not/porn > /var/www/app/filethatrootcanwriteto.log
add a user
02 * * * * root /usr/bin/curl --basic --user 'user:pass' http://localhost/not/porn > /var/www/app/filethatrootcanwriteto.log
可以有 2 个 php.ini 文件,一个用于 apache,一个用于 CLI。
locate php.ini 应该可以找到两者,我建议您先检查那里。
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.
这也可以通过使用 ob_start() 和 ob_end_flush() 缓冲 PHP 输出来避免curl 过早返回状态。
This can also be avoided by buffering your PHP output using ob_start() and ob_end_flush() to prevent curl from returning status prematurely.