Php Magento:监视所有cron作业的执行时间?

Php Magento:监视所有cron作业的执行时间?,php,magento,Php,Magento,我继承了一个基于Magento Enterprise 1.9的网站,该网站有很多cron作业定期运行 这些cron作业由第三方模块配置,不属于Magento的核心 一组作业涉及将数据文件从Magento导出和导入到仓库管理系统,有时cron作业会陷入某种循环中,并会持续处理数小时,而它们本应只需要几分钟 我想以某种方式监控这些作业需要多长时间,但不需要修改每个脚本本身。如果可能的话,也许是某种观察者 有什么想法吗?有关Magento中计划作业的调度和运行的基本信息,可以从core\u sched

我继承了一个基于Magento Enterprise 1.9的网站,该网站有很多cron作业定期运行

这些cron作业由第三方模块配置,不属于Magento的核心

一组作业涉及将数据文件从Magento导出和导入到仓库管理系统,有时cron作业会陷入某种循环中,并会持续处理数小时,而它们本应只需要几分钟

我想以某种方式监控这些作业需要多长时间,但不需要修改每个脚本本身。如果可能的话,也许是某种观察者


有什么想法吗?

有关Magento中计划作业的调度和运行的基本信息,可以从
core\u schedule
表中获得。请注意,根据“系统>配置>系统>Cron计划”中的设置添加和删除条目。可以从任何给定模块的config.xml中的
节点确定原始计划作业配置(类、方法和cron表达式)

其中许多可以通过使用在管理中可视化和交互


要捕获性能(内存使用情况、启动/停止时间),可能需要在这些cron启动的脚本中删除一些日志调用。

构建一个脚本,该脚本执行根据cron\u计划创建的格式化表

我知道关于发布链接的通常做法,但MagentoCommerce.com可能不会很快消失,而在这里发布代码是一个皇家皮塔。代码见底部。进入系统配置cron设置,并告诉它将信息保存24小时

现在,您可以在下面的输出示例中看到正在计划的所有内容和已执行的所有内容

很抱歉链接上出现了问题,我试图将最重要的东西移到这里,但错过了这一个。幸运的是,它仍在其中一个站点上运行

<?php

/******************************************************
 * Magento Log File Contents Monitor.
 * Released under the Digital Damnation Copyright
 * Free to do whatever the 7734 you want to do with it.
 * provided without warranty or support
 ******************************************************/

/***********************
 * Scan Magento local.xml file for connection information
 * Run out of password protected scripts/ directory
 ***********************/

if (file_exists('../app/etc/local.xml')) {

$xml = simplexml_load_file('../app/etc/local.xml', NULL, LIBXML_NOCDATA);

$db['host'] = $xml->global->resources->default_setup->connection->host;
$db['name'] = $xml->global->resources->default_setup->connection->dbname;
$db['user'] = $xml->global->resources->default_setup->connection->username;
$db['pass'] = $xml->global->resources->default_setup->connection->password;
$db['pref'] = $xml->global->resources->db->table_prefix;

$tables = array(
   'dataflow_batch_export',
   'dataflow_batch_import',
   'log_customer',
   'log_quote',
   'log_summary',
   'log_summary_type',
   'log_url',
   'log_url_info',
   'log_visitor',
   'log_visitor_info',
   'log_visitor_online',
   'catalog_compare_item',
   'report_event',
   'report_compared_product_index',
   'report_viewed_product_index',
   'sales_flat_quote',
   'sales_flat_quote_address',
   'sales_flat_quote_address_item',
   'sales_flat_quote_item',
   'sales_flat_quote_item_option',
   'sales_flat_quote_payment',
   'sales_flat_quote_shipping_rate'
);

} 

else {
    exit('Failed to open ../app/etc/local.xml');
}

/** Get current date, time, UTC and offset **/

$date   = date("Y-m-d");
$time   = date("H:i:s T");
$offset = date("P");
$utc    = gmdate("H:i:s");

/***********************
 * Start HTML output
 ***********************/

echo '<html><head><title>Magento Log File Contents on ' . $date . ' ' . $time . '</title>
<meta http-equiv="refresh" content="30">
<style type="text/css">html {width: 100%; font-family:  Arial,Helvetica, sans-serif;}
body {line-height:1.0em; font-size: 100%;}
table {border-spacing: 1px;}
th.stattitle {text-align: left; font-size: 100%; font-weight: bold; color: white; background-color: #101010;}
th {text-align: center; font-size: 90%; font-weight: bold; padding: 5px; border-bottom: 1px solid black; border-left: 1px solid black; }
td {font-size: 90%; padding: 4px; border-bottom: 1px solid black; border-left: 1px solid black;}
</style>
</head><body>';

/** Output title, connection info and cron job monitor runtime **/

echo '<h2>Magento Log File Contents Report</h2><h3>Connection: '.$db['user'].'@'.$db['host'].'&nbsp;&nbsp;&ndash;&nbsp;&nbsp;Database: ' . $db['name'] . '</h3>';
echo '<h3>Runtime: ' . $date . '&nbsp;&nbsp;&nbsp;' .$time . '&nbsp;&nbsp;&nbsp;' . $utc . ' UTC</h3>';
echo '<h4>Note: Your timezone offset is ' . $offset . ' hours from UTC</h4>';

/** Connect to database **/

$conn = mysql_connect($db['host'],$db['user'],$db['pass']);
@mysql_select_db($db['name']) or die(mysql_error());

/***********************
 * Get table record counts
 ***********************/

echo '<table><tbody><tr><th class="stattitle" colspan="2">Log Tables</th></tr>';
echo '<tr><th>Table</th><th>Row Count</th></tr>';

foreach($tables as $tblname) {
   $result  = mysql_query('SELECT COUNT(*) FROM ' . $db['pref'] . $tblname) or die(mysql_error());
   $numrows = mysql_fetch_array($result);
   $num     = $numrows[0];

   /* Table output */
   echo '<tr>';
   echo '<td>'.$db['pref'].$tblname.'</td>';
   echo '<td align="right">'.$num.'</td>'; 
   echo '</tr>';                 
}

echo '</tbody></table></body></html>';

/***********************
 * End of report
 ***********************/

mysql_close($conn);
?> 


我有一个客户机也有同样的问题,他们没有看到作业运行了多长时间,也没有很好地了解cron中发生了什么。有一些解决方案,但他们没有完全做到他们想要的,所以我最终建立了一个小型服务,我称之为。任何人都可以免费使用。

我还对这些过程的更多见解感兴趣。有一件事可能会有所帮助,那就是core_cron数据库表。它包含关于运行cron脚本和一些错误的信息,但不太多。仅供参考,这个问题不一定非常适合SO,这就是为什么会有。不客气。这对于使触发器cron进程正常运行非常有帮助。网络服务器有时是偏执狂和泡泡糖包装纸的奇怪混合物。我遇到过拒绝从crontab运行Magento的cron.sh的系统,因此您最终直接触发cron.php。另外,很高兴看到,在模块设置xml中启用cron部分实际上是拿起了它的末端并触发了。我设法找到了一个不同的源代码,但我感谢查找和添加代码的努力:)它肯定会帮助其他人。