由于内部服务器错误,Cronjob 超时
我的托管提供商只允许我每 2 小时运行一次 cronjob。由于我需要它每秒运行一次,因此我制作了一个将运行 2 小时的页面。另外,我是和ZF一起开发的;所以页面需要引导,这意味着 cronjob 需要调用一个网址。
到目前为止,我的 bash 脚本每两个小时运行一次:
#!/bin/bash
wget "http://www.mysite.co.za/ajax/cron"
但是,它会在几分钟后停止,并出现以下错误:
--2011-02-04 09:32:32-- http://www.mysite.co.za/ajax/cron
Resolving www.mysite.co.za... 123.40.97.157
Connecting to www.mysite.co.za|123.40.97.157|:80... connected.
HTTP request sent, awaiting response... 500 Internal Server Error
2011-02-04 09:37:33 ERROR 500: Internal Server Error
我对 cronjobs/bash 脚本了解不多,但我认为它超时了?谁能证实这一点吗?如果是这样,我将研究curl_mutl_init以发回响应并同时保持进程处于活动状态 - 我认为我无法访问进程控制功能。
如果有人有任何提示/建议,请不要犹豫。
My hosting provider only allows me to run a cronjob every 2 hours. Since I need it to run every second, I've made a page that will run for 2 hours. Also, I developed with ZF; so the page needs to be bootstrapped, which means the cronjob needs to call a web address.
So far my bash script runs every two hours:
#!/bin/bash
wget "http://www.mysite.co.za/ajax/cron"
However, it stops after a few minutes with the following error:
--2011-02-04 09:32:32-- http://www.mysite.co.za/ajax/cron
Resolving www.mysite.co.za... 123.40.97.157
Connecting to www.mysite.co.za|123.40.97.157|:80... connected.
HTTP request sent, awaiting response... 500 Internal Server Error
2011-02-04 09:37:33 ERROR 500: Internal Server Error
I don't know much about cronjobs/bash scripts, but I think it's timing out? Can anyone confirm this? If so, I'll look into curl_mutl_init to send a response back and keep the process alive at the same time - I don't think I'll have access to process control functions.
If anyone has any tips/advice, please don't hesitate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
几条评论意见:
1。引导程序
使用引导程序的 ZF 任务并不需要通过 HTTP 请求来实现。您可以运行使用引导程序的命令行任务。
在您的
my_script.php
中 - 通常放置在目录scripts
或application/scripts
中 - 您可以从与您的网站相同的内容开始应用程序的index.php
文件:检查/设置include_path
、检查/设置APPLICATION_ENV
、检查/设置APPLICATION_PATH
和实例化您的Zend_Application
对象。唯一的区别是您调用了
$application->bootstrap()
,但不继续执行$application->run()
代码>.事实上,由于某些引导资源可能仅用于网络应用程序,因此您可以调用:这样您就不会引导不需要的资源。
然后继续执行您的任务的细节。
2.命令行
如果您希望将脚本设计为接受参数,可以使用
Zend_Console_GetOpt
。非常酷。3.每秒一次?
当然,我不知道您的用例或具体需求,但每秒运行一次作业对我来说确实听起来很多。是否可以将其中一些任务放入队列中,并以您的主机允许的频率消耗队列?
希望这有帮助!
Several comments observations:
1. Bootstrapping
It is not the case that a ZF task using the bootstrap needs to come via an HTTP request. You can run command-line tasks that use your bootstrap.
In your
my_script.php
- typically placed in directoryscripts
or inapplication/scripts
- you can start with much of the same content as your web app'sindex.php
file: check/setinclude_path
, check/setAPPLICATION_ENV
, check/setAPPLICATION_PATH
, and instantiate yourZend_Application
object.The only difference is that you call
$application->bootstrap()
, but don't proceed along to$application->run()
. In fact, since some of the bootstrapped resources might be needed only for the web app, you can call:so you don't bootstrap resources you don't need.
Then go on to perform the specifics of your task.
2. Command line
If you wish to design your script to accept parameters, you can use
Zend_Console_GetOpt
. It's pretty cool.3. Once-per-second?
Of course, I don't know your use-case or your specific need, but running a job once per second sure sounds like a lot to me. Is it possible to put some of these tasks into a queue and consume the queue with a frequency allowable under your hosting?
Hope this helps!
无论您使用什么后端服务器端脚本,都要求它运行无限长的时间或忽略用户中止。
你的网络服务器可能也有一些设置来增加超时时间..(Apache有它,我已经使用过这个功能)
whatever backend server side script you are using, ask it to run for infinite amount of time OR ignore user abort.
Your webserver might have some settings to increase time out period too.. (Apache has it, I've used this feature )
如果您有一个需要每秒运行一次的 cron,那么最好使用页面加载来触发脚本。因此,每次有人请求新页面时,它都会运行该脚本。无论如何,Cron 无法以少于一分钟的间隔运行。
您还可以编写一个 php 脚本,其中包含以下代码
Continuous.php:
bash 脚本来查看您的 php 脚本是否正在运行
checkContinously.sh
希望有所帮助!
If you have a cron that needs to be run every second, It might be better to use page loads to fire off your script. So each time someone requests a new page, it would run the script. Cron isn't capable of running on intervals any less than a minute anyway.
You can also write a php script that has the following code
continuous.php:
bash script to see if your php script is running
checkContinuous.sh
Hope that helps!