PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php-cron工作正在magento网站中工作-但未找到心跳大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

对于我们的magento网站,突然的cron工作停止了工作.

当我们尝试使用以下命令设置cron作业时,错误为:

-bash: */5: No such file or directory

命令:

*/5 * * * * PHP -f /var/www/html/sitename/cron.PHP

编辑

我们在同一服务器上有2个站点.

我们有一个自定义模块来检查cron是否正常工作.

一个站点中,我们收到以下消息

php-cron工作正在magento网站中工作-但未找到心跳

在另一个站点中,此消息:

php-cron工作正在magento网站中工作-但未找到心跳

php-cron工作正在magento网站中工作-但未找到心跳

cron.PHP

<?PHP
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * it is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.PHP
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    Mage
 * @package     Mage
 * @copyright  Copyright (C) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license    http://opensource.org/licenses/osl-3.0.PHP  Open Software License (OSL 3.0)
 */

// Change current directory to the directory of current script
chdir(dirname(__FILE__));


require 'app/Mage.PHP';

if (!Mage::isInstalled()) {
    echo "Application is not installed yet, please complete install wizard first.";
    exit;
}

// Only for urls
// Don't remove this
$_SERVER['SCRIPt_name'] = str_replace(basename(__FILE__), 'index.PHP', $_SERVER['SCRIPt_name']);
$_SERVER['SCRIPT_FILename'] = str_replace(basename(__FILE__), 'index.PHP', $_SERVER['SCRIPT_FILename']);

Mage::app('admin')->setUseSessionInUrl(false);

umask(0);

$disabledFuncs = explode(',', ini_get('disable_functions'));
$isSHellDisabled = is_array($disabledFuncs) ? in_array('sHell_exec', $disabledFuncs) : true;
$isSHellDisabled = (Stripos(PHP_OS, 'win') === falsE) ? $isSHellDisabled : true;
$isSHellDisabled = true;

try {
    if (Stripos(PHP_OS, 'win') === falsE) {
        $options = getopt('m::');
        if (isset($options['m'])) {
            if ($options['m'] == 'always') {
                $cronMode = 'always';
            } elseif ($options['m'] == 'default') {
                $cronMode = 'default';
            } else {
                Mage::throwException('Unrecognized cron mode was defined');
            }
        } else if (!$isSHellDisabled) {
            $filename = basename(__FILE__);
            $baseDir = dirname(__FILE__);
            sHell_exec("/bin/sh $baseDir/cron.sh $filename -mdefault 1 > /dev/null 2>&1 &");
            sHell_exec("/bin/sh $baseDir/cron.sh $filename -malways 1 > /dev/null 2>&1 &");
            exit;
        }
    }

    Mage::getConfig()->init()->loadEventObservers('crontab');
    Mage::app()->addEventArea('crontab');
    if ($isSHellDisabled) {
        Mage::dispatchEvent('always');
        Mage::dispatchEvent('default');
    } else {
        Mage::dispatchEvent($cronModE);
    }
} catch (Exception $E) {
    Mage::printexception($E);
    exit(1);
}

?>

<?PHP
Mage::log('cron working', null, 'cron.log');
?>

当我在cron.PHP的末尾添加代码并在浏览器中运行文件时,它显示:2016年5月17日,星期二,07:12:03 PM,因此cron正在运行.但是为什么找不到心跳?

try {
   $myFile = "cronlog.txt";
   $fh = fopen($myFile, 'w');
   $StringData = date('l jS \of F Y h:i:s A');
   fwrite($fh, $StringData);
   fclose($fh);
} catch (Exception $E) {
   Mage::printexception($E);
}

编辑2

在电子邮件中,我们收到这些错误

执行searchsphinx_check_daemon时发生Cron错误

exception 'Mage_Core_Exception' with message 'Too late for the schedule.' inapp/Mage.PHP:595
Stack trace:
#0app/code/community/Aoe/scheduler/Model/Observer.PHP(47): Mage::throwException('Too late for th...')
#1app/code/core/Mage/Core/Model/App.PHP(1338): Aoe_scheduler_Model_Observer->dispatch(Object(Varien_Event_Observer))
#2app/code/core/Mage/Core/Model/App.PHP(1317): Mage_Core_Model_App->_callObserverMethod(Object(Aoe_scheduler_Model_Observer), 'dispatch', Object(Varien_Event_Observer))
#3app/Mage.PHP(448): Mage_Core_Model_App->dispatchEvent('default', Array)
#4cron.PHP(76): Mage::dispatchEvent('default')
#5 {main}

cron日志

2016-05-24T12:30:02+00:00 DEBUG (7): Start: captcha_delete_old_attempts
2016-05-24T12:30:02+00:00 DEBUG (7): Stop: captcha_delete_old_attempts
2016-05-24T12:30:02+00:00 DEBUG (7): Start: mstcore_logger_cron
2016-05-24T12:30:02+00:00 DEBUG (7): Stop: mstcore_logger_cron
2016-05-24T12:30:02+00:00 DEBUG (7): Start: newsletter_send_all
2016-05-24T12:30:02+00:00 DEBUG (7): Stop: newsletter_send_all
2016-05-24T12:30:02+00:00 DEBUG (7): Start: searchsphinx_check_daemon
2016-05-24T12:30:02+00:00 DEBUG (7): Stop: searchsphinx_check_daemon
2016-05-24T12:30:02+00:00 DEBUG (7): Start: searchsphinx_reindex_delta_job
2016-05-24T12:30:02+00:00 DEBUG (7): Stop: searchsphinx_reindex_delta_job
2016-05-24T12:30:02+00:00 DEBUG (7): Start: xmlconnect_notification_send_all
2016-05-24T12:30:02+00:00 DEBUG (7): Stop: xmlconnect_notification_send_all
2016-05-24T12:30:03+00:00 DEBUG (7): Start: aoescheduler_heartbeat
2016-05-24T12:30:03+00:00 DEBUG (7): Stop: aoescheduler_heartbeat
2016-05-24T12:30:03+00:00 DEBUG (7): Start: captcha_delete_expired_images
2016-05-24T12:30:03+00:00 DEBUG (7): Job "captcha_delete_expired_images" (id: 133636) is locked. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Stop: captcha_delete_expired_images
2016-05-24T12:30:03+00:00 DEBUG (7): Start: captcha_delete_old_attempts
2016-05-24T12:30:03+00:00 DEBUG (7): Job "captcha_delete_old_attempts" (id: 133638) is locked. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Stop: captcha_delete_old_attempts
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:31" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:32" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:33" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "aoescheduler_heartbeat" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "aoescheduler_heartbeat" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "aoescheduler_heartbeat" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "captcha_delete_expired_images" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "aoescheduler_heartbeat" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "aoescheduler_heartbeat" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "aoescheduler_heartbeat" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "captcha_delete_expired_images" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Generated schedule. NeWest task is scheduled at "2016-05-24 12:49:00". (Duration: 0.37 seC)
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "newsletter_send_all" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "newsletter_send_all" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "newsletter_send_all" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:31" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:32" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:33" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:34" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:36" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:37" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:38" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:39" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:41" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:42" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "newsletter_send_all" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:43" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "newsletter_send_all" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:44" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "newsletter_send_all" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:46" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:47" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:48" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:49" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_reindex_delta_job" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:31" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:32" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:33" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:34" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:36" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:37" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:38" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "xmlconnect_notification_send_all" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:39" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "xmlconnect_notification_send_all" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:41" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:42" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "xmlconnect_notification_send_all" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:43" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:44" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Generated schedule. NeWest task is scheduled at "2016-05-24 12:49:00". (Duration: 0.21 seC)
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:46" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:47" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:48" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_check_daemon" at "2016-05-24 12:49" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "searchsphinx_reindex_delta_job" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "xmlconnect_notification_send_all" at "2016-05-24 12:35" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "xmlconnect_notification_send_all" at "2016-05-24 12:40" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Pending schedule for "xmlconnect_notification_send_all" at "2016-05-24 12:45" already exists 1 times. Skipping.
2016-05-24T12:30:03+00:00 DEBUG (7): Generated schedule. NeWest task is scheduled at "2016-05-24 12:49:00". (Duration: 0.28 seC)
2016-05-24T12:31:02+00:00 DEBUG (7): Start: mstcore_logger_cron
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: mstcore_logger_cron
2016-05-24T12:31:02+00:00 DEBUG (7): Start: newsletter_send_all
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: newsletter_send_all
2016-05-24T12:31:02+00:00 DEBUG (7): Start: aoescheduler_heartbeat
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: aoescheduler_heartbeat
2016-05-24T12:31:02+00:00 DEBUG (7): Start: searchsphinx_reindex_delta_job
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: searchsphinx_reindex_delta_job
2016-05-24T12:31:02+00:00 DEBUG (7): Start: captcha_delete_expired_images
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: captcha_delete_expired_images
2016-05-24T12:31:02+00:00 DEBUG (7): Start: xmlconnect_notification_send_all
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: xmlconnect_notification_send_all
2016-05-24T12:31:02+00:00 DEBUG (7): Start: captcha_delete_old_attempts
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: captcha_delete_old_attempts
2016-05-24T12:31:02+00:00 DEBUG (7): Start: searchsphinx_check_daemon
2016-05-24T12:31:02+00:00 DEBUG (7): Stop: searchsphinx_check_daemon
2016-05-24T12:32:02+00:00 DEBUG (7): Start: searchsphinx_check_daemon
2016-05-24T12:32:02+00:00 DEBUG (7): Stop: searchsphinx_check_daemon

解决方法:

*/5 * * * * date >> /var/www/html/magento/var/log/cron.log;/bin/sh -f /var/www/html/magento/cron.sh >> /var/www/html/magento/var/log/cron.log;

我们还以apache用户身份运行crontab,因为apache是​​我们所有magento文件的所有者:

sudo crontab -e -u apache

大佬总结

以上是大佬教程为你收集整理的php-cron工作正在magento网站中工作-但未找到心跳全部内容,希望文章能够帮你解决php-cron工作正在magento网站中工作-但未找到心跳所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: