Kohana 中的 Cron 作业

发布于 2024-10-20 15:11:37 字数 411 浏览 8 评论 0原文

如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

罗罗贝儿 2024-10-27 15:11:38

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.

め可乐爱微笑 2024-10-27 15:11:38

所以如果有一个特殊的命令
调用 cron 作业,我没有添加它
(因为我不知道那会是什么)

愚蠢的问题 - 您是否已将 wget 命令添加到 crontab 或类似命令中?

另一方面,如果您想要创建一个“穷人的 cron”,您可以尝试创建一个在每个页面加载时运行的挂钩,并检查上次运行作业的时间,也许将最后一个时间戳存储在文件或数据库中。

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)

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.

以为你会在 2024-10-27 15:11:38

我必须在curl中使用cURL作为我的fire-this-script命令

例如:

30     18     *     *     * curl "http://domain.com/controller/method"

php和wget不起作用,即使在调用index.php并按照上面的建议添加uri时也是如此。

另外,仅供参考,最透明的测试方法就是从 SSH 手动运行该行来查看结果。一旦我确认它在那里工作,我就把它放入 cron 中。

I had to use cURL as my fire-this-script command in curl

Ex:

30     18     *     *     * curl "http://domain.com/controller/method"

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文