問(wèn)題描述
我正在嘗試編寫(xiě)一個(gè) cronjob 控制器,因此我可以調(diào)用一個(gè)網(wǎng)站并執(zhí)行所有模塊 cronjob.php.現(xiàn)在我的問(wèn)題是我該怎么做?
I am trying to write a cronjob controller, so I can call one website and have all modules cronjob.php executed. Now my problem is how do I do that?
curl 是一種選擇,所以我也可以計(jì)算錯(cuò)誤和成功嗎?
Would curl be an option, so I also can count the errors and successes?
[更新]
我想我解釋得還不夠多.
I guess I have not explained it enough.
我想要做的是有一個(gè)我可以從 http://server/cronjob 調(diào)用的文件,然后讓它執(zhí)行每一個(gè)/application/modules/*/controller/CronjobController.php 或者有另一種方式來(lái)做,所以所有的 cronjobs 不是在一個(gè)地方,而是在模塊所在的同一個(gè)地方.這會(huì)給我?guī)?lái)好處,如果模塊不存在,它不會(huì)嘗試運(yùn)行其 cronjob.
What I want to do is have one file which I can call like from http://server/cronjob and then make it execute every /application/modules/*/controller/CronjobController.php or have another way of doing it so all the cronjobs aren't at one place but at the same place the module is located. This would offer me the advantage, that if a module does not exist it does not try to run its cronjob.
現(xiàn)在我的問(wèn)題是你將如何執(zhí)行所有模塊 CronjobController 或者你是否會(huì)以完全不同的方式執(zhí)行它以便它仍然保持模塊化?
Now my question is how would you execute all the modules CronjobController or would you do it a completly different way so it still stays modular?
我希望能夠給出有多少cronjobs成功運(yùn)行,有多少?zèng)]有
And I want to be able to giveout how many cronjobs ran successfully and how many didn't
推薦答案
經(jīng)過(guò)一些研究和大量的拖延,我得出一個(gè)簡(jiǎn)單的結(jié)論,即 ZF 化的 cron 腳本應(yīng)該包含您的 Zend 框架應(yīng)用程序的所有功能 - 沒(méi)有所有視圖的東西.我通過(guò)在我的應(yīng)用程序目錄中創(chuàng)建一個(gè)新的 cronjobfoo.php 文件來(lái)實(shí)現(xiàn)這一點(diǎn).然后我從以下方面取了最低限度:-我的前端控制器(index.php)-我的bootstrap.php
After some research and a lot procrastination I came to the simple conclusion that a ZF-ized cron script should contain all the functionality of you zend framework app - without all the view stuff. I accomplished this by creating a new cronjobfoo.php file in my application directory. Then I took the bare minimum from: -my front controller (index.php) -my bootstrap.php
我取出了所有的視圖內(nèi)容,專注于保持環(huán)境設(shè)置、數(shù)據(jù)庫(kù)設(shè)置、自動(dòng)加載器和 &注冊(cè)表設(shè)置.我不得不花一點(diǎn)時(shí)間來(lái)更正文檔根變量并刪除一些從引導(dǎo)程序復(fù)制的 OO 功能.
I took out all the view stuff and focused on keeping the environment setup, db setup, autoloader, & registry setup. I had to take a little time to correct the document root variable and remove some of the OO functionality copied from my bootstrap.
在那之后,我只是編碼了..在我的情況下,它正在編譯和通過(guò)電子郵件發(fā)送夜間報(bào)告.使用 Zend_Mail 很棒.當(dāng)我確信我的腳本按照我想要的方式工作時(shí),我只是將它添加到我的 crontab 中.
After that I just coded away.. in my case it was compiling and emailing out nightly reports. It was great to use Zend_Mail. When I was confident that my script was working the way I wanted, I just added it my crontab.
祝你好運(yùn)!
這篇關(guān)于使用 Zend Framework 創(chuàng)建 cronjob的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!