How to directly RUN a function inside a controller class via cron?
In magento i tried to setup cron as following.
<crontab>
<jo开发者_运维知识库bs>
<inchoo_birthday_send>
<schedule><cron_expr>0 1 * * *</cron_expr></schedule>
</inchoo_birthday_send>
</jobs>
</crontab>
Here it calls model but how can i directly call a function inside the controller. For example
class Mage_Adminhtml_Inchoo_BirthdayController extends Mage_Adminhtml_Controller_Action
{
public function sendAction($strFname)
{
// this has to be called from cron in magento.
}
}
How i can directly call the sendAction action function inside the above controller from cron. In other words how this sendAction initiated from cron directly. I have to run the conroller function directly instead of model.
Please help me
you should treat this class as ordinary model.
$observer = Mage::getModel('birthday/observer');
$observer->sendBirthayEmail();
Hope this is what You need.
Edit
$curl = new Varien_Http_Adapter_Curl();
$curl->setConfig(array('timeout' => 20));
$curl->write(Zend_Http_Client::GET, 'http://www.stackoverflow.com');
$curl->read(); //or without this line
This should do the trick, if You want more info, please see content of Varien_Http_Adapter_Curl
class.
If You will only invoke one time sendAction
inside cron model, then it's ok...
But i suggest to use cron itself, because it is more efficient rather than using Curl multiple times.
You are doing it wrong :) if you need to call a controller with all dispatchers and events you should use wget or curl to call your action. If you don't need all events and dispatchers to fire then your method is just in wrong place
精彩评论