[英]Magento cron.php throws error when called via Cron or php
我最近使用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
我怀疑编码可能有问题。 谁能帮我这个 ?
编码可能不如换行符。
不同的操作系统使用 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无法解释以Windows CRLF行结尾的shebang行 ,因此可以解释shebang问题。
但是,PHP旨在在其解释器中处理CRLF,因此我怀疑这是第一个问题。 您没有确切描述文件的执行方式,因此我假设您正在遵循这些说明 。 如果我的假设是正确的,那么您将使用此处描述的三个cron行: http : //devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-cron.html#create定时工作 。 在那种情况下,我猜想使用了错误的PHP版本。 我认为在WebFaction上,如果使用/usr/local/php
的默认PHP版本是5.2,而Magento 2.1需要PHP 5.6。 这可能是您的问题,但没有更多细节,很难确定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.