[think\exception\ErrorException]
Uncaught think\exception\ErrorException: Cannot modify header information - headers already sent by (output started at /home/wwwroot/thinkswoole/app/server/controller/Chatroom.php:84) in /home/wwwroot/thinkswoole/app/server/BaseServer.php:39
Stack trace:
#0 [internal function]: think\Error::appError(2, 'Cannot modify h...', '/home/wwwroot/t...', 39, Array)
#1 /home/wwwroot/thinkswoole/app/server/BaseServer.php(39): header('Content-Type:ap...')
#2 /home/wwwroot/thinkswoole/app/server/BaseServer.php(24): app\server\BaseServer->outputJson(Array)
#3 /home/wwwroot/thinkswoole/app/server/controller/Chatroom.php(86): app\server\BaseServer->outputSuccess('{"type":"say","...')
#4 {main}
thrown
so 看到这里发现了重要的问题 Cannot modify header information - headers already sent by ……大致意思是说:不能够修改头信息 头信息已经被设置过了,然后…… 。因为是使用了swoole 的常驻进程,普通php 代码执行完一次就结束了。 header 输出格式只设置一次,但是 常驻进程下就会被设置多次,导致该错误的出现。
解决办法在类构造方法里执行一次就ok 。 因为即便是方法多次调用,但对象仅创建一次,即便你创建多个对象, 也不会影响,因为每个对象都是独立的。
常驻进程下 header头被多次设置的问题
最新推荐文章于 2021-05-24 15:15:35 发布