swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 786 forks source link

Composer 安装后,启动服务报Cannot use Swoole\Coroutine\Redis as Redis错误 #125

Closed fatjiong closed 6 years ago

fatjiong commented 6 years ago

问题描述

环境:macos php版本:

    PHP 7.0.0 (cli) (built: Dec  2 2015 13:35:31) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

swoft版本:1.0 描述: 1.使用composer create-project swoft/swoft swoft dev-master初始化项目 2.使用php swoft start 开始项目会出现报错,不晓得是不是我php版本低的原因,报错信息如下:

`Fatal error: Cannot use Swoole\Coroutine\Redis as Redis because the name is already in use in /Users/fatjiong/Sites/swoft/vendor/swoft/redis/src/RedisConnect.php on line 9`

解决: 经查看是"./vendor/swoft/redis/src/RedisConnect.php"类内的第九行:use Swoole\Coroutine\Redis; 引用命名空间重复了,我做了下修改,修改成以下这种:

line 9:`use Swoole\Coroutine\Redis as newRedis;`
line 37:`$redis  = new newRedis();` 
用as取别名避免命名空间重复,不知道这样子处理是否可行?
PS:跑docker安装的时候没有发现该问题。
重新执行`php swoft start`,框架已经可以正常执行:
`
Information Panel                     
******************************************************************
* http | Host: 0.0.0.0, port: 8888, Model: 3, type: 1, Worker: 1
* tcp  | Enable: 1, host: 0.0.0.0, port: 8099, type: 1, Worker: 1
******************************************************************
`
stelin commented 6 years ago

我们跟踪下这个问题

huangzhhui commented 6 years ago

请使用 swoft/redis v1.0.4 版本以上再试一下