laravel .env多项目串值

 版权声明:    https://blog.csdn.net/qq_29785317/article/details/81068733
(When you have two or more sites on one server, the sites’s .env will affect each other)

这个问题多半发生在 Apache上,因为加载.env文件的时候用了 getenv() 和 setenv() 。 
这两个函数不是线程安全的,它会将.env文件里面的值设置在进程级别的环境中(process-wide variable) 
Apache 使用线程处理请求,当一个进程同时有几个线程的时候,就比较容易发生 ‘串值’ 的情况

例子:串库

不过这种情况在php-fpm+nginx上面好像并不怎么会受影响(我搜索相关问题时,问题提到环境都是 apache,没有找到nginx的案例),因为nginx使用进程来处理php请求,进程间相互独立,所以就算getenv()/setenv() 将变量设置在进程环境中,也没有太大影响,不会 ‘串值’

参考 :这个

This issue is related to a webserver hosting several requests within the same process. This causes problems with other things too, like setlocale(). Other configurations, like nginx + php-fpm, is not affected by this problem since it executes one process per request.

另外很多人建议由于getenv()/setenv()不是线程安全的原因,生产环境不要使用.env文件,对于laravel的应用来说,应该对配置文件进行缓存来代替,执行 php artisan config:cache 来进行生产,尽量避免使用 env() 函数
--------------------- 
作者:_内啥玩意啊 
来源:CSDN 
原文:https://blog.csdn.net/qq_29785317/article/details/81068733 
版权声明:本文为博主原创文章,转载请附上博文链接!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值