Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教一个关注注册laravels全局实例的问题 #41

Closed
mountainguan opened this issue May 25, 2018 · 3 comments
Closed

请教一个关注注册laravels全局实例的问题 #41

mountainguan opened this issue May 25, 2018 · 3 comments
Labels
question Further information is requested

Comments

@mountainguan
Copy link

情景:
我的程序里面有一个服务需要加载字典,字典内容多需要加载的时间长。因此我想把服务像laravel的app一样被laravels从入口处加载,这样就可以一次加载,后面所有请求都直接调用,免去每个请求都把它实例化一次,把字典重新读取一次这么浪费时间。

问题:
那么我应该怎么把这个加载字典的工具,跟laravel的框架一起实例化加载到swoole中运行呢?

@hhxsv5 hhxsv5 added the question Further information is requested label May 25, 2018
@hhxsv5
Copy link
Owner

hhxsv5 commented May 25, 2018

编写一个类来存储你对应的字典,然后通过ServiceProvider注册单例到Laravel,这样每个worker公用此单例。

@mountainguan
Copy link
Author

我查了一下,swoole是不会主动释放global和static的数据。所以我直接用global存储一次,后面就到处都可以调用了

@hhxsv5
Copy link
Owner

hhxsv5 commented May 25, 2018

可以,你知道这些是常驻的就行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants