Magento cron job

2019-01-15 22:31发布

问题:

I have configured my server (CPanel) to run cron.sh in magento root folder every 5 min. But it doesnt works and cron_schedule table in database is empty. Here is my config.xml

<config>
<modules>
    <Company_Facebookreview>
        <version>1.0.0</version>
    </Company_Facebookreview>
</modules>
<global>
    <models>
        <facebookreview>
            <class>Company_Facebookreview_Model</class>
            <resourceModel>facebookreview_mysql4</resourceModel>
        </facebookreview>
        <facebookreview_mysql4>
            <class>Company_Facebookreview_Model_Mysql4</class>
            <entities>
                <facebookreview>
                    <table>facebookreview</table>
                </facebookreview>
            </entities>
        </facebookreview_mysql4>
    </models>
    <resources>
        <facebookreview_setup>
            <setup>
                <module>Company_Facebookreview</module>
                <class>Mage_Sales_Model_Resource_Setup</class>
            </setup>
        </facebookreview_setup>
    </resources>
    <helpers>
        ...
    </helpers>
    <blocks>
        ...
    </blocks>
    <events>
        <sales_order_place_after>
            <observers>
                <place_order_after>
                    <type>singleton</type>
                    <class>Company_Facebookreview_Model_Observer</class>
                    <method>save</method>
                </place_order_after>
            </observers>
        </sales_order_place_after>
    </events>
</global>
<crontab>
    <jobs>
        <facebookreview>
            <schedule>
                <cron_expr>*/5 * * * *</cron_expr>
            </schedule>
            <run>
                <model>facebookreview/observer::methodName</model>
            </run>
        </facebookreview>
    </jobs>
</crontab>

and here is my Company/Facebookreview/Model/Observer.php

class Company_Facebookreview_Model_Observer extends Varien_Event_Observer
{
public function save(Varien_Event_Observer $observer) {

}
public function methodName($schedule) {
    Mage::log('cron working fine');//cache is disabled and var folder has 777 permissions and var folder hasnt log folder
}
}

cache is disabled and var folder has 777 permissions and var folder hasnt log folder. I am using Magento Comunity 1.9. What i am doing wrong ? please help...

回答1:

If your table cron_schedule table is empty then most probably either the system cron is not working or the magento cron is not added to it.

Please cross check this. You can add Magento Cron to system cron like this:

*/5 * * * *  /bin/sh /path/to/magento/cron.sh

OR you can add using PHP way.

Also, to confirm that the magento cron is working fine and the issue is due to either of the above mentioned cases, try to open following URL in browser:

www.MAGENTOSITE.COM/cron.php

If running this URL creates entry in cron_schedule then you need to check the above mentioned things.



回答2:

I have two suggestions.

Update cron.php

If you're using Magento 1.8, then this will explain what you need to do: http://www.a2hosting.com/kb/installable-applications/optimization-and-configuration/magento1/cron-jobs-do-not-run-on-magento-1-8-after-upgrade

Make sure you're using the right version of php

It might simply be you're using an old version of php! By default, on 1and1 in my case, just using the php command gets v4.4.9. I have to explicitly force php v5 and then it works!

I'd also recommend installing Fabrizio Branca's AOE Scheduler extension