Filesystem.php 中的 ErrorException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29169892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:17:05  来源:igfitidea点击:

ErrorException in Filesystem.php

phplaravelsessionlaravel-5

提问by Peder Wessel

Issue with session storage

会话存储问题

Session storage not working with my Laravel 5. Used it for a month without problems. But since latest upload to web server I get the following response on every page.

会话存储不适用于我的 Laravel 5。使用它一个月没有问题。但是自从最近上传到网络服务器后,我在每个页面上都会收到以下响应。

ErrorException in Filesystem.php line 74:
file_put_contents(): Exclusive locks are not supported for this stream

Many posts on the internet are indicating to remove the reference to

互联网上的许多帖子都表示要删除对

$lock on line 74 in Filesystem.php

Seems like a quick fix which will lead to other issues down the road...

似乎是一个快速解决方案,它将导致其他问题......

How do I take care of the root cause?

我如何处理根本原因?

References

参考

https://stackoverflow.com/questions/29023948/laravel-5-file-put-contents-exclusive-locks-are-not-supported-for-this-strehttps://laracasts.com/discuss/channels/general-discussion/l5-new-install-error

https://stackoverflow.com/questions/29023948/laravel-5-file-put-contents-exclusive-locks-are-not-supported-for-this-stre https://laracasts.com/discuss/channels/general -讨论/l5-new-install-error

回答by maleeb

after update do

更新后做

chmod -R gu+w storage

chmod -R guo+w storage

php artisan cache:clear

回答by paulalexandru

If you use Laravel 5.2.0 you've probably ignored the storagefolder in the .gitignorefile. The thing is that when you run composer installon your server not all the files from the storage folder are created, you should check those !

如果您使用 Laravel 5.2.0,您可能忽略了storage文件中的.gitignore文件夹。问题是,当您composer install在服务器上运行时,并非存储文件夹中的所有文件都被创建,您应该检查那些!

In my case my storage folder contained only the logsfolder without appand frameworkfolders. You need to create those manually so you should have this structure at the end:

就我而言,我的存储文件夹仅包含logs没有文件夹appframework文件夹的文件夹。您需要手动创建这些,所以最后应该有这个结构:

storage
  - app
  - framework
    - cache 
    - sessions
    - views
  - logs

Don't forget to make the storagefolder writable !

不要忘记使storage文件夹可写!

回答by Peder Wessel

Had to do with the hosting. My cloud service did not support exclusive locks. I exchanged

与托管有关。我的云服务不支持排他锁。我交换了

return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);

return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);

to

return file_put_contents($path, $contents, $lock ? LOCK_SH : 0);

return file_put_contents($path, $contents, $lock ? LOCK_SH : 0);

on line 74 of Filesystem.php

在 Filesystem.php 的第 74 行

回答by shamanSK

thanks @peder-wessel. Your answer is the cause explanation but not a permanent solution and will work until we update the vendors again as Filesystem.php file is inside Laravel vendor directory. One day, when we composer updateit will cause problem again. :(

谢谢@peder-wessel。您的答案是原因解释,但不是永久解决方案,并且会一直有效,直到我们再次更新供应商,因为 Filesystem.php 文件位于 Laravel 供应商目录中。总有一天,我们composer update会再次引发问题。:(

However I was able to find out that this issue is caused because Session is saved to file. I changed this from

但是我能够发现这个问题是因为会话被保存到文件引起的。我改变了这个

'driver' => 'file',

to

'driver' => 'cookie',

in /app/config/session.php

/app/config/session.php

Maybe laravel creators should add this to configuration too, as not all (shared) hostings provide exclusive lock rights

也许 Laravel 创建者也应该将其添加到配置中,因为并非所有(共享)主机都提供独占锁定权限

回答by Hassan Gilak

I had problem with publishing my assets from my package with this error file_put_contents(): Exclusive locks are not supported for this stream

我在从我的包中发布我的资产时遇到了这个错误 file_put_contents(): 此流不支持独占锁的问题

this package helps NoLock

这个包有助于NoLock