【php】php5.6+.27-nts + TP5.0.20 + think-queuev1.1.6 + redis2.4.0 + phpredis2.2.7,实现消息队列功能

1、指导地址:GIT --》 》 https://github.com/coolseven/notes/blob/master/thinkphp-queue/README.md

2、TP5.0.*建议安装composer,并且composer.json设置如下:

"require": {
        "php": ">=5.4.0",
        "topthink/framework": "5.0.*",
        "topthink/think-image": "^1.0",
        "topthink/think-captcha": "1.*",
        "topthink/think-mongo": "1.*",
        "topthink/think-migration": "1.*",
        "topthink/think-queue": "v1.1.6",
        "topthink/think-helper": "1.*"
    },

项目根目录,执行命令:composer install

不建议直接   composer install topthink/think-queue ; 因为如果你版本不是5.1+的话,这样会报错,版本低了。

安装redis  -- 》 https://github.com/dmajkic/redis/downloads 随便下,不要太老的,在D:\phpStudy\ 新建Redis目录,存放与win操作系统相符的解压缩包redis (32 or 64)   、 

  phpredis -- 》http://pecl.php.net    搜索redis 下载对应版本,丢ext/  , 修改php.ini  增加 extension=php_redis.dll   重启。

 

3、查看queue命令是否存在: php think list ;查看think-queue包是否存在,不存在去 https://packagist.org/packages/topthink/think-queue#v1.1.6 composer.json加载

如上图,恭喜你,queue命令加载成功。

4、 然后就是按照git上面文章来,就行了。基本没什么问题,我是成功了的。

控制器效果图:

 

队列效果图:

 

 

 

 

附录主要遇到的问题:

1)thinkphp5.0无法使用think-queue包,php think queue:work命令不存在(1、composer.json的think-queue版本高了;2、application被修改了)

解决方案: http://www.imooc.com/wenda/detail/518588

解决了,是不小心把application重命名为app了,在think中加载了application目录,然后提示不存在的错误信息

2)建议设置成 redis 或者数据库类型,不要直接使用默认的sync,因为效果不太好(sync是同步的,直接到位了)

 

posted @ 2019-05-30 11:50  PHP急先锋  阅读(517)  评论(1编辑  收藏  举报