【问题标题】:magento cron job and error_log file too largemagento cron 作业和 error_log 文件太大
【发布时间】:2014-09-10 16:05:05
【问题描述】:

我最近安装了 Magento 社区版,除了一些设计工作和一些扩展的安装外,没有做任何密集的工作。我今天查看了 error_log 文件,它似乎是 6gb,几乎用尽了我的托管空间。我认为这很不寻常,因为安装的其余部分小于 2gb,所以我打开了错误日志文件(请注意,它的一部分,因为它太大了)然后出现了:

[12-Mar-2014 20:31:33 UTC] PHP 注意:未定义索引:SCRIPT_NAME 在 /home/zongulsz/public_html/cron.php 第 39 行

[12-Mar-2014 20:31:33 UTC] PHP 注意:未定义索引: /home/zongulsz/public_html/cron.php 第 40 行中的 SCRIPT_FILENAME

[08-Apr-2014 10:13:22 America/Chicago] PHP 警告:PHP 启动: 无法加载动态库 '/opt/alt/php53/usr/lib64/php/modules/memcached.so' - libmemcached.so.11:无法打开共享对象文件:没有这样的文件或 第 0 行 Unknown 中的目录

一遍又一遍地重复相同的条目。

这是我在 cpanel 中看到的 cron 作业命令:

分钟 小时 日 月 工作日 命令操作
13,29,31,49 * * * * php> /home/zongulsz/public_html/cron.php > /dev/null

这是 cron.php 文件:

1   <?php
2   /**
3    * Magento
4    *
5    * NOTICE OF LICENSE
6    *
7    * This source file is subject to the Open Software License (OSL 3.0)
8    * that is bundled with this package in the file LICENSE.txt.
9    * It is also available through the world-wide-web at this URL:
10   * http://opensource.org/licenses/osl-3.0.php
11   * If you did not receive a copy of the license and are unable to
12   * obtain it through the world-wide-web, please send an email
13   * to license@magentocommerce.com so we can send you a copy immediately.
14   *
15   * DISCLAIMER
16   *
17   * Do not edit or add to this file if you wish to upgrade Magento to newer
18   * versions in the future. If you wish to customize Magento for your
19   * needs please refer to http://www.magentocommerce.com for more information.
20   *
21   * @category   Mage
22   * @package    Mage
23   * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24   * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
25   */
26
27  // Change current directory to the directory of current script
28  chdir(dirname(__FILE__));
29
30  require 'app/Mage.php';
31
32  if (!Mage::isInstalled()) {
33      echo "Application is not installed yet, please complete install wizard first.";
34      exit;
35  }
36
37  // Only for urls
38  // Don't remove this
39  $_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']);
40  $_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']);
41
42  Mage::app('admin')->setUseSessionInUrl(false);
43
44  umask(0);
45
46  $disabledFuncs = explode(',', ini_get('disable_functions'));
47  $isShellDisabled = is_array($disabledFuncs) ? in_array('shell_exec', $disabledFuncs) : true;
48  $isShellDisabled = (stripos(PHP_OS, 'win') === false) ? $isShellDisabled : true;
49
50  try {
51      if (stripos(PHP_OS, 'win') === false) {
52          $options = getopt('m::');
53          if (isset($options['m'])) {
54              if ($options['m'] == 'always') {
55                  $cronMode = 'always';
56              } elseif ($options['m'] == 'default') {
57                  $cronMode = 'default';
58              } else {
59                  Mage::throwException('Unrecognized cron mode was defined');
60              }
61          } else if (!$isShellDisabled) {
62              $fileName = basename(__FILE__);
63              $baseDir = dirname(__FILE__);
64              shell_exec("/bin/sh $baseDir/cron.sh $fileName -mdefault 1 > /dev/null 2>&1 &");
65              shell_exec("/bin/sh $baseDir/cron.sh $fileName -malways 1 > /dev/null 2>&1 &");
66              exit;
67          }
68      }
69
70      Mage::getConfig()->init()->loadEventObservers('crontab');
71      Mage::app()->addEventArea('crontab');
72      if ($isShellDisabled) {
73          Mage::dispatchEvent('always');
74          Mage::dispatchEvent('default');
75      } else {
76          Mage::dispatchEvent($cronMode);
77      }
78  } catch (Exception $e) {
79      Mage::printException($e);
80      exit(1);
81  }
82

【问题讨论】:

  • 向您的主机发送一张带有错误日志的票。 $_SERVER['SCRIPT_NAME'] 和 $_SERVER['SCRIPT_FILENAME'] 没有设置是他们的问题,因为您的服务器上没有 memcached。要成功运行 Magento,您通常需要足够的托管服务提供商。
  • 我的托管服务提供商似乎对此感到困惑,我不确定这是否是我的责任,或者他们的系统因不允许 Magento 正常运行而出现故障。我会再次与他们取得联系。谢谢

标签: php magento cron


【解决方案1】:

尝试将ini_set('display_errors',0);error_reporting(0); 放在cron.php 文件的开头。

【讨论】:

  • 这会关闭错误报告以终止您收到的那些未定义的索引错误。这是由于在 php.ini 中打开了未定义的变量以及 E_NOTICE。或者,您可以只添加 error_reporting(E_ALL &amp; ~E_NOTICE);,这将保留除 E_NOTICE 之外的所有错误报告。
  • 谢谢肖恩。我只是担心关闭错误报告是否是正确的做法,而不是真正修复 error_log 报告的内容。你有什么建议?
  • 关闭E_NOTICE 并不会对该文件产生太大影响。如果这两个通知是唯一出现的通知,则添加 error_reporting(E_ALL &amp; ~E_NOTICE); 将解决问题并且仅影响此文件。您仍然会看到所有其他错误。
  • 我想我应该问的是,这两个错误是什么,它们有什么影响?它们是系统需要的关键功能,还是只是一些对 Magento 系统功能没有影响的错误?
  • 这只是一个警告,让您知道您有未定义的变量。除了填满你的日志,它对你的系统没有其他不良影响。
【解决方案2】:

在服务器级别应该有一个设置应该设置为禁止与通知相关的日志。

简而言之,您要么在服务器级别执行此操作,要么通过一些 PHP 代码执行此操作。

【讨论】:

    猜你喜欢
    • 2013-04-05
    • 2016-04-05
    • 2011-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多