欧云服务器 发表于 2024-11-3 13:05:01

智简魔方定时任务异常怎么办?不能定时通知服务器到期信息

本帖最后由 欧云官方号 于 2024-11-3 13:10 编辑

如图,在智简魔方这套服务器对接销售的系统中,创建定时任务可以自动在服务器快到期前提醒用户及时续费。



但是这个定时任务明明创建了,手动执行无数次,还是提示失败怎么办?
打开宝塔的计划任务,查看日志如下:

PHP Fatal error:Uncaught think\exception\ErrorException: Method ReflectionParameter::getClass() is deprecated in /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php:464
Stack trace:
#0 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(464): think\Error::appError()
#1 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(435): think\Container->bindParams()
#2 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(282): think\Container->invokeClass()
#3 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(132): think\Container->make()
#4 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/exception/Handle.php(42): think\Container::get()
#5 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Error.php(52): think\exception\Handle->report()
#6 : think\Error::appException()
#7 {main}
thrown in /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php on line 464

Fatal error: Uncaught think\exception\ErrorException: Method ReflectionParameter::getClass() is deprecated in /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php:464
Stack trace:
#0 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(464): think\Error::appError()
#1 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(435): think\Container->bindParams()
#2 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(282): think\Container->invokeClass()
#3 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(132): think\Container->make()
#4 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/exception/Handle.php(42): think\Container::get()
#5 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Error.php(52): think\exception\Handle->report()
#6 : think\Error::appException()
#7 {main}
thrown in /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php on line 464
PHP Fatal error:Uncaught think\exception\ErrorException: Method ReflectionParameter::getClass() is deprecated in /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php:464
Stack trace:
#0 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(464): think\Error::appError()
#1 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(435): think\Container->bindParams()
#2 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(282): think\Container->invokeClass()
#3 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(132): think\Container->make()
#4 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/exception/Handle.php(42): think\Container::get()
#5 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Error.php(52): think\exception\Handle->report()
#6 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Error.php(91): think\Error::appException()
#7 : think\Error::appShutdown()
#8 {main}
thrown in /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php on line 464

Fatal error: Uncaught think\exception\ErrorException: Method ReflectionParameter::getClass() is deprecated in /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php:464
Stack trace:
#0 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(464): think\Error::appError()
#1 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(435): think\Container->bindParams()
#2 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(282): think\Container->invokeClass()
#3 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php(132): think\Container->make()
#4 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/exception/Handle.php(42): think\Container::get()
#5 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Error.php(52): think\exception\Handle->report()
#6 /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Error.php(91): think\Error::appException()
#7 : think\Error::appShutdown()
#8 {main}
thrown in /home/www/wwwroot/魔方网站目录/vendor/thinkphp/library/think/Container.php on line 464
----------------------------------------------------------------------------
★ Successful
----------------------------------------------------------------------------分析日志可以发现,主要是/vendor/thinkphp/library/think/Container.php 中使用的 ReflectionParameter::getClass() 方法已被弃用(deprecated)导致的。
这个方法在 PHP 8.0 开始被弃用,意味着它在将来的 PHP 版本中可能会被移除。
原因很简单,就是你同时安装了php7.2、7.3、8.0等太多版本,主要就是最新安装的8.0导致的。
因为每次安装新版本后,系统默认的命令行会切换为最新安装的php版本,比如有时候我们先安装8.0在安装7.3就不会出现这个错误异常的。
不相信的话可以打开命令行,输入php -v就能看到当前版本号如图,我明明也安装了7.3,却只显示8.0


这时候有两种解决方法

方法一(不推荐)
宝塔面板==》网站==》php项目==》高级设置==》php命令行版本==》设置为php73

缺点 万一后面需要用到其他的php版本,安装后,这里就变了,忘了设置,就又开始失败而不自知了

方法二(★★★★★推荐)
直接修改定时任务命令,指定php版本
比如我的命令如下,开头只有php就是说采用的系统默认的php版本(方法一中设置的)
php /home/www/wwwroot/你的网站目录名/think cron指定php为7.3,则修改开头的php为php73,修改后如下
php73 /home/www/wwwroot/你的网站目录名/think cron缺点 万一后面换服务器时,你给这个程序装了比如php7.2魔方也是支持的,但是开头的php73没改成php72,那因为你没安装php73也会导致失败

这时候再到计划任务里,点击日志==》清空==》执行==》刷新,就会看到已经成功了的样子
打开魔方后台刷新,可以发现也恢复正常了

总结
一般我们使用魔方,建议都是php73,因为版本新点,支持东西更多。一般不会换别的版本,换别的你也用不了,根本打不开。所以方法二是我最推荐的。
页: [1]
查看完整版本: 智简魔方定时任务异常怎么办?不能定时通知服务器到期信息