【问题标题】:Magento cron.php throws error when called via Cron or phpMagento cron.php 在通过 Cron 或 php 调用时抛出错误
【发布时间】:2016-09-06 20:20:41
【问题描述】:

我最近使用 Magento 托管了我的网站,在设置我的 cron.php 后,我得到以下输出:

/home/xxx/webapps/abc/cron.php: line 1: ?php
: No such file or directory
/home/xxx/webapps/abc/cron.php: line 2: /**
: No such file or directory
/home/xxx/webapps/abc/cron.php: line 3: bin: command not found
/home/xxx/webapps/abc/cron.php: line 4: $'*\r': command not found
/home/xxx/webapps/abc/cron.php: line 5: bin: command not found
/home/xxx/webapps/abc/cron.php: line 6: $'*\r': command not found
/home/xxx/webapps/abc/cron.php: line 7: syntax error near unexpected token `('
/home/xxx/webapps/abc/cron.php: line 7: ` * This source file is subject to the Open Software License (OSL 3.0)

'

我在 Webfaction 上托管此问题,并且似乎此错误仅在 Webfaction 上发生。我在另一个服务上托管的另一个网站(使用相同的 Magento 版本)运行良好。

即使我删除了 cron.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-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

我还尝试将“shebang”放在

#!/usr/local/bin/php

得到这个结果:

/usr/local/bin/php^M: bad interpreter: No such file or directory

我怀疑编码可能有问题。谁能帮我解决这个问题?

【问题讨论】:

  • 您确定可以正确访问php,并且您使用的是正确的版本吗?

标签: php magento cron webfaction


【解决方案1】:

可能不像换行符那样编码。

不同的操作系统use different combinations ASCII 中的回车和换行字符。 Windows 使用回车 + 换行(ASCII 代码 0x0D+0x)作为换行符。 Linux/Unix 单独使用换行符(ASCII 代码 0x0A)。

当您看到^M 时,通常会告诉您文本中有一个不可打印的字符(除非您确实有 Caret + M,这很不寻常)。您可以在此处查看控制字符及其“插入符号”的映射(锚点后的第一个表,列 [b]):https://en.wikipedia.org/wiki/ASCII#Control_characters

鉴于 ^M 是回车字符,它在 Linux 中不使用并且在 Windows 中的换行之前使用,我的第一个想法是您的文件正在 Windows 上进行编辑,然后推送到 Linux 服务器。 Linux can't interpret a shebang line with a Windows CRLF line ending,这样就解释了shebang问题。

但是,PHP 旨在在其解释器中处理 CRLF,所以我怀疑这是第一个问题。你没有准确描述文件是如何执行的,所以我假设你是following these instructions。如果我的假设是正确的,那么您正在使用此处描述的三个 cron 行:http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-cron.html#create-the-cron-job。在这种情况下,我猜是使用了错误的 PHP 版本。我认为在 WebFaction 上,如果您使用 /usr/local/php,则默认 PHP 版本是 5.2,而 Magento 2.1 需要 PHP 5.6。这可能是你的问题,但没有更多细节,很难确定。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-25
    • 1970-01-01
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多