简体   繁体   中英

Magento cron.php throws error when called via Cron or php

I recently hosted my website using Magento, upon setting up my cron.php i get the following output :

/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)

'

I host this on Webfaction, and it appears that this error only happen on Webfaction. My other website (using the same Magento version) which is hosted on another service runs just fine.

Even after i removed the following lines on cron.php, it still does not work:

/**
 * 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)
 */

I've also tried to put "shebang" just before the

#!/usr/local/bin/php

And get this result:

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

I suspect that there might be something wrong with the encoding. Can anyone help me with this ?

Probably not the encoding as much as the newlines.

Different operating systems use different combinations of the Carriage Return and Line Feed characters in ASCII. Windows uses Carriage Return + Line Feed (ASCII Codes 0x0D+0x) as its delimiter of newlines. Linux/Unix uses Line Feed alone (ASCII Code 0x0A).

When you see ^M , it is usually telling you that an unprintable character is in the text (unless you literally have Caret + M, which would be unusual). You can see a map of the control characters and their "caret notation" here (first table after the anchor, column [b]): https://en.wikipedia.org/wiki/ASCII#Control_characters

Given that ^M is the Carriage Return character which isn't used in Linux and is used prior to Line Feed in Windows, my first thought is that your file is being edited on Windows and then pushed to a Linux server. Linux can't interpret a shebang line with a Windows CRLF line ending , so that explains the shebang issue.

However, PHP is designed to handle CRLF in their interpreter, so I doubt that is the first issue. You didn't describe exactly how the file is executed, so I presume that you are following these instructions . If my assumption is correct, then you are using the three cron lines described here: http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-cron.html#create-the-cron-job . In that case, I'd guess that the wrong PHP version is being used. I think on WebFaction, the default PHP version if you use /usr/local/php is 5.2 and Magento 2.1 requires PHP 5.6. This may be your issue, but without more details, it is tough to pin down.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM