CakePHP 定时任务 returns 500 错误
CakePHP cronjob returns 500 error
我的 crontab 中有以下条目:
SHELL="/bin/bash"
* * * * * /home/peepzcoz/public_html/testapp/bin/cake ClientReminder
* * * * * /home/peepzcoz/public_html/testapp/bin/cake StaffReminder
* * * * * /home/peepzcoz/public_html/testapp/bin/cake ProcessJobRequests
所有这些都将结果通过电子邮件发送到邮箱。但是对于他们所有人,我都收到以下消息:
Status: 500 Internal Server Error
X-Powered-By: PHP/7.2.8
Content-type: text/html; charset=UTF-8
调试在我的 app.php
配置文件中打开。
如果我像这样更改 crontab:
SHELL="/bin/bash"
* * * * * /usr/local/bin/php /home/peepzcoz/public_html/testapp/bin/cake ClientReminder
* * * * * /usr/local/bin/php /home/peepzcoz/public_html/testapp/bin/cake StaffReminder
* * * * * /usr/local/bin/php /home/peepzcoz/public_html/testapp/bin/cake ProcessJobRequests
我得到这个结果:
################################################################################
#
# Cake is a shell script for invoking CakePHP shell commands
#
# CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
# Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
#
# Licensed under The MIT License
# For full copyright and license information, please see the LICENSE.txt
# Redistributions of files must retain the above copyright notice.
#
# @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
# @link https://cakephp.org CakePHP(tm) Project
# @since 1.2.0
# @license https://opensource.org/licenses/mit-license.php MIT License
#
################################################################################
# Canonicalize by following every symlink of the given name recursively
canonicalize() {
NAME=""
if [ -f "$NAME" ]
then
DIR=$(dirname -- "$NAME")
NAME=$(cd -P "$DIR" > /dev/null && pwd -P)/$(basename -- "$NAME")
fi
while [ -h "$NAME" ]; do
DIR=$(dirname -- "$NAME")
SYM=$(readlink "$NAME")
NAME=$(cd "$DIR" > /dev/null && cd $(dirname -- "$SYM") > /dev/null && pwd)/$(basename -- "$SYM")
done
echo "$NAME"
}
CONSOLE=$(dirname -- "$(canonicalize "[=14=]")")
APP=$(dirname "$CONSOLE")
if [ $(basename [=14=]) != 'cake' ]
then
exec php "$CONSOLE"/cake.php $(basename [=14=]) "$@"
else
exec php "$CONSOLE"/cake.php "$@"
fi
exit
如果我直接在终端中运行它,它执行得很好,它们都按预期执行。
如何获得调试输出以便至少知道问题出在哪里?我在这台服务器上看不到错误日志,蛋糕日志文件夹中的错误日志是空的。
我还能检查什么?
好的,我通过下载最新版本的 bin/cake
解决了这个问题。但这并没有那么简单。
首先,我将其下载到我的windows机器上,然后将其上传到服务器,这将行尾更改为windows行尾。这导致了一个新错误:
/usr/bin/env: sh
: No such file or directory
所以我尝试 运行 dos2unix bin/cake
,但是 dos2unix
没有安装在共享服务器上。
我通过对原始文件执行 wget 并覆盖 bin/cake
文件解决了这个问题。这解决了它,我的 crons 开始 运行ning。
有点跑题了,不过你可以通过添加 DEBUG=1
到你的 cronjob 来查看调试信息:
* * * * * DEBUG=1 /home/peepzcoz/public_html/testapp/bin/cake ClientReminder
我的 crontab 中有以下条目:
SHELL="/bin/bash"
* * * * * /home/peepzcoz/public_html/testapp/bin/cake ClientReminder
* * * * * /home/peepzcoz/public_html/testapp/bin/cake StaffReminder
* * * * * /home/peepzcoz/public_html/testapp/bin/cake ProcessJobRequests
所有这些都将结果通过电子邮件发送到邮箱。但是对于他们所有人,我都收到以下消息:
Status: 500 Internal Server Error
X-Powered-By: PHP/7.2.8
Content-type: text/html; charset=UTF-8
调试在我的 app.php
配置文件中打开。
如果我像这样更改 crontab:
SHELL="/bin/bash"
* * * * * /usr/local/bin/php /home/peepzcoz/public_html/testapp/bin/cake ClientReminder
* * * * * /usr/local/bin/php /home/peepzcoz/public_html/testapp/bin/cake StaffReminder
* * * * * /usr/local/bin/php /home/peepzcoz/public_html/testapp/bin/cake ProcessJobRequests
我得到这个结果:
################################################################################
#
# Cake is a shell script for invoking CakePHP shell commands
#
# CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
# Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
#
# Licensed under The MIT License
# For full copyright and license information, please see the LICENSE.txt
# Redistributions of files must retain the above copyright notice.
#
# @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
# @link https://cakephp.org CakePHP(tm) Project
# @since 1.2.0
# @license https://opensource.org/licenses/mit-license.php MIT License
#
################################################################################
# Canonicalize by following every symlink of the given name recursively
canonicalize() {
NAME=""
if [ -f "$NAME" ]
then
DIR=$(dirname -- "$NAME")
NAME=$(cd -P "$DIR" > /dev/null && pwd -P)/$(basename -- "$NAME")
fi
while [ -h "$NAME" ]; do
DIR=$(dirname -- "$NAME")
SYM=$(readlink "$NAME")
NAME=$(cd "$DIR" > /dev/null && cd $(dirname -- "$SYM") > /dev/null && pwd)/$(basename -- "$SYM")
done
echo "$NAME"
}
CONSOLE=$(dirname -- "$(canonicalize "[=14=]")")
APP=$(dirname "$CONSOLE")
if [ $(basename [=14=]) != 'cake' ]
then
exec php "$CONSOLE"/cake.php $(basename [=14=]) "$@"
else
exec php "$CONSOLE"/cake.php "$@"
fi
exit
如果我直接在终端中运行它,它执行得很好,它们都按预期执行。
如何获得调试输出以便至少知道问题出在哪里?我在这台服务器上看不到错误日志,蛋糕日志文件夹中的错误日志是空的。
我还能检查什么?
好的,我通过下载最新版本的 bin/cake
解决了这个问题。但这并没有那么简单。
首先,我将其下载到我的windows机器上,然后将其上传到服务器,这将行尾更改为windows行尾。这导致了一个新错误:
/usr/bin/env: sh
: No such file or directory
所以我尝试 运行 dos2unix bin/cake
,但是 dos2unix
没有安装在共享服务器上。
我通过对原始文件执行 wget 并覆盖 bin/cake
文件解决了这个问题。这解决了它,我的 crons 开始 运行ning。
有点跑题了,不过你可以通过添加 DEBUG=1
到你的 cronjob 来查看调试信息:
* * * * * DEBUG=1 /home/peepzcoz/public_html/testapp/bin/cake ClientReminder