Kohana 中的 Cron 作业
如何在 Kohana 中创建 cron 作业?我设置了一个从 Controller_Base 延伸出来的常规控制器,并运行了命令行: /usr/bin/wget http://domain/controller/custom_cron
但我无法让它工作。它只是不执行。没有错误,什么都没有。我没有在控制器中放入任何特殊代码...只是运行程序所需的代码。因此,如果有一个特殊的命令来调用 cron 作业,我没有添加它(因为我不知道它是什么)。
另外,我需要它来进行 MySQL 调用,所以我需要包含数据库信息和连接以及不包含的内容(如果它不会自动执行此操作)。我正在研究一个定制模型。我将如何包含它(如果它不会自动执行)。
谢谢。
How do you create a cron job in Kohana? I setup a regular controller which extends off the Controller_Base and I ran the command line:
/usr/bin/wget http://domain/controller/custom_cron
But I can't get it to work. It just doesn't execute. No error, nothing. I didn't put any special code in my controller ... just what I need to run my program. So if there is like a special command to call a cron job, I didn't add it (cause I don't know what it would be).
Also, I need it to make MySQL calls so I would need to include the db info and connection and what not (if it doesn't do that automatically). And I work off a custom model. How would I include that (if it doesn't do it automatically).
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
php /path/to/index.php --uri=controller/action/etc/etc
像这样调用它几乎使它的行为与在 Web 环境中完全相同。唯一的区别是请求的协议是“cli”。如果您要生成链接,则需要记住这一点。
php /path/to/index.php --uri=controller/action/etc/etc
Calling it like this pretty much makes it act exactly like in a web environment. The only difference is the protocol for requests is 'cli'. You'll need to keep that in mind if you are generating links.
愚蠢的问题 - 您是否已将 wget 命令添加到 crontab 或类似命令中?
另一方面,如果您想要创建一个“穷人的 cron”,您可以尝试创建一个在每个页面加载时运行的挂钩,并检查上次运行作业的时间,也许将最后一个时间戳存储在文件或数据库中。
Daft question - have you added that wget command to crontab or similar?
If on the other hand you're looking to make a "poor man's cron", you could try creating a hook that runs on every page load and checks the last time the job was run, perhaps storing the last timestamp in a file or database.
我必须在curl中使用cURL作为我的fire-this-script命令
例如:
php和wget不起作用,即使在调用index.php并按照上面的建议添加uri时也是如此。
另外,仅供参考,最透明的测试方法就是从 SSH 手动运行该行来查看结果。一旦我确认它在那里工作,我就把它放入 cron 中。
I had to use cURL as my fire-this-script command in curl
Ex:
php and wget didn't work, even when calling index.php and adding the uri as suggested above.
Also, FYI, Most transparent way to test this was just running the line from SSH manually to see what the results were. Once I confirmed it was working there, then I put it in the cron.