当通过Cron或php调用时,Magento cron.php会抛出错误

时间:2016-09-06 02:29:54

标签: php magento cron webfaction

我最近使用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

我怀疑编码可能有问题。任何人都可以帮我这个吗?

1 个答案:

答案 0 :(得分:0)

可能不是新编码的编码。

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

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

鉴于^ M是Carriage Return字符,它在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。 可能可能是您的问题,但如果没有更多细节,则很难确定。

相关问题