使用FileMonitor时报错

Kevin_

项目结构

报错信息

PHP Fatal error:  Cannot redeclare check_files_change() (previously declared in /www/wwwroot/learnOperGateWayWorker/GatewayWorker/Applications/FileMonitor/start.php:26) in /www/wwwroot/learnOperGateWayWorker/GatewayWorker/Applications/YourApp/start.php on line 49

Fatal error: Cannot redeclare check_files_change() (previously declared in /www/wwwroot/learnOperGateWayWorker/GatewayWorker/Applications/FileMonitor/start.php:26) in /www/wwwroot/learnOperGateWayWorker/GatewayWorker/Applications/YourApp/start.php on line 49

过程复现

  1. 在GatewayWorker目录下运行“php start.php start”,就会报上面的错误
1540 3 0
3个回答

blogdaren

看上去是/path/to/YourApp/start.php脚本中重定义了funciton check_file_changes(), 这个函数在FileMonitor包中已经定义过了,不清楚你要干啥,换个函数名就行了。

  • Kevin_ 2021-12-18

    我想实现热更新,check_files_change这个方法只在FileMonitor/start.php中定义了一次,按照“https://github.com/walkor/workerman-filemonitor”做的,代码是从这个地址下载下来的,无改动

  • blogdaren 2021-12-18

    说的是/path/to/YourApp/start.php脚本没有改动过?

  • Kevin_ 2021-12-18

    YourApp目录下没有start.php,只有start_businessworker.php、start_gateway.php、start_register.php,这三个文件只改了start_gateway.php文件里的协议,报错的不是YouApp下的文件,报错的是FileMonitor下的start.php

  • blogdaren 2021-12-18

    GatewayWorker下的start.php

  • Kevin_ 2021-12-18

    不是GatewayWorker下的start.php,是GatewayWorker\Applications\FileMonitor\start.php,这个是workerman的一个文件监控组件,报错的就是这个组件

  • blogdaren 2021-12-18

    一开始说了函数check_file_changes()本来就在官方FileMonitor文件监控包里呢,不是什么包报错,而是有其他的脚本里有重定义的同名函数,这是本质,具体是哪个脚本里自己排查下就完事了啊,别整复杂了。

  • Kevin_ 2021-12-18

    我写的所有脚本里都没有check_files_change这个函数,这个只在官方的文件监控包里有,我搜索了整个项目,也显示只在官方的文件监控包里有

  • Kevin_ 2021-12-18

    谢谢前辈的热心回答,我找到问题了
    问题确如报错所示,是函数冲突问题,并给出了两个文件的位置
    但是我的“Applications/YourApp/”目录下没有start.php文件,所以迷茫了。原因是我在本地使用phpstorm写代码自动同步到服务器,之前在YourApp下创建了一个start.php,后来把文件移走了,但是这项修改没有被同步到服务器端,导致了上面的报错,而我排查的时候是根据本地的文件进行排查的,最后检查了服务器上面的文件,已经解决了问题,官方的FileMonitor组件非常好用,再次感谢blogdaren前辈的回答

xiuwang
PHP Fatal error:  Cannot redeclare check_files_change() (previously declared in /www/wwwroot/learnOperGateWayWorker/GatewayWorker/Applications/FileMonitor/start.php:26) in /www/wwwroot/learnOperGateWayWorker/GatewayWorker/Applications/YourApp/start.php on line 49

翻译过来就是不能在YourApp/start.php文件的第49行重新定义 check_files_change() (因为check_files_change()在FileMonitor/start.php第26行定义过)。报错文件、行数、重复的函数名都提示给你了,应该很好找了

  • Kevin_ 2021-12-18

    26行是定义的函数,49行是一个括号结尾,代码是官方的,地址:https://github.com/walkor/workerman-filemonitor/blob/master/Applications/FileMonitor/start.php

  • xiuwang 2021-12-18

    请贴出你本地这两个文件内容

  • xiuwang 2021-12-18

    Applications/FileMonitor/start.php 和 Applications/YourApp/start.php

  • Kevin_ 2021-12-18

    谢谢前辈的热心回答,我找到问题了
    问题确如报错所示,是函数冲突问题,并给出了两个文件的位置
    但是我的“Applications/YourApp/”目录下没有start.php文件,所以迷茫了。原因是我在本地使用phpstorm写代码自动同步到服务器,之前在YourApp下创建了一个start.php,后来把文件移走了,但是这项修改没有被同步到服务器端,导致了上面的报错,而我排查的时候是根据本地的文件进行排查的,最后检查了服务器上面的文件,已经解决了问题,官方的FileMonitor组件非常好用,再次感谢xiuwang前辈的回答

Tinywan

默认debug模式就是自动会更新的,为什么还要这样子搞

  • Kevin_ 2021-12-19

    debug模式会自动热更新吗?

年代过于久远,无法发表回答
🔝