Store.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * This file is part of workerman.
  4. *
  5. * Licensed under The MIT License
  6. * For full copyright and license information, please see the MIT-LICENSE.txt
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @author walkor<walkor@workerman.net>
  10. * @copyright walkor<walkor@workerman.net>
  11. * @link http://www.workerman.net/
  12. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Config;
  15. /**
  16. * 存储配置
  17. * 这是一个GatewayWorker的配置文件,
  18. * 用于配置key/value存储,支持File、Memcache、Redis
  19. * 生产环境建议用Redis存储,即配置Store::$driver=self::DRIVER_REDIS;
  20. * 默认是File存储,存储在本地磁盘上
  21. *
  22. * 作用:此存储用于存储Gateway进程的内部通讯地址,以及每个客户端client_id
  23. * 对应的Gateway地址。
  24. * 当Gateway启动后每个gateway进程会将自己的内部通讯地址放到这个存储里面
  25. * 当BusinessWorker进程启动后,会从这个存储中读取所有Gateway通讯地址,
  26. * 并与其通过socket相连,这样Gateway与BusinessWorker便可以通讯了
  27. *
  28. * 如果有多个GatewayWorker应用时,每个应用的这个配置都应该不同,
  29. * 否则会导致多个应用间数据互通
  30. * 如果有多个GatewayWorker应用时,配置细节如下
  31. * 当Store::$driver=self::DRIVER_FILE时,每个应用的Store::$storePath应该不同
  32. * 当Store::$driver=self::DRIVER_MC/DRIVER_REDIS时,每个应用的
  33. * Store::$gateway的ip或者端口应该不同
  34. *
  35. * 注意:当使用Redis存储时,Redis服务端redis-server的timeout配置成0
  36. * redis扩展git地址https://github.com/phpredis/phpredis
  37. * redis扩展安装方法 pecl install redis
  38. *
  39. * @author walkor
  40. */
  41. class Store
  42. {
  43. // 使用文件存储,注意使用文件存储无法支持workerman分布式部署
  44. const DRIVER_FILE = 1;
  45. // 使用memcache存储,支持workerman分布式部署
  46. const DRIVER_MC = 2;
  47. // 使用redis存储(推荐),支持workerman分布式部署
  48. const DRIVER_REDIS = 3;
  49. // DRIVER_FILE 或者 DRIVER_MC 或者 DRIVER_REDIS(推荐)
  50. public static $driver = self::DRIVER_REDIS;
  51. // 框架自身配置,$driver为DRIVER_MC/DRIVER_REDIS时需要配置memcached/redis服务端ip和端口
  52. /*public static $gateway = array(
  53. '10.47.1.73:6379',
  54. );*/
  55. // 存储房间相关数据,$driver为DRIVER_MC/DRIVER_REDIS时需要配置memcached/redis服务端ip和端口
  56. public static $redis = array(
  57. '127.0.0.1:6379',
  58. 'crazy_coin2020',
  59. );
  60. // $driver为DRIVER_FILE时要配置此项,实际配置在最下面一行
  61. public static $storePath = '';
  62. }
  63. // 默认系统临时目录下
  64. //Store::$storePath = 'F:/workerman-chat/';//sys_get_temp_dir().