Laravel/Heroku,没有用于会话的此类文件或目录 [英] Laravel/Heroku, no such file or directory for sessions

查看:74
本文介绍了Laravel/Heroku,没有用于会话的此类文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在heroku上运行我的应用程序,但是对于某些请求(仅POST,GET运行正常),我的Ajax POST请求出现以下错误:

I'm trying to run my application on heroku, but for some requests (only POST, GET are working fine), I've got the following error on my Ajax POST request:

Error: Request failed with status code 419

当我检查heroku日志时,出现此错误:

When I check heroku logs, I get this error:

     production.ERROR: file_put_contents(/app/storage/framework/sessions/r9yIHf3WlKIzROWGPlVOk59rwr6tVyAeCLuJ9wWx): 
failed to open stream: No such file or directory
{"userId":1,"email":"xxx@gmail.com","exception":"[object] (ErrorException(code: 0): 
file_put_contents(/app/storage/framework/sessions/r9yIHf3WlKIzROWGPlVOk59rwr6tVyAeCLuJ9wWx): failed to open stream: No such file or directory at /app/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:122)

我已经检查过,目录/storage/framework/sessions存在.

I've checked, the directory /storage/framework/sessions is existing.

我尝试运行chmod 777 -R/(但仍然是此问题)

I've tried to run chmod 777 -R / (but still this issue)

我尝试了以下命令:

php artisan optimize
php artisan config:clear
php artisan cache:clear
php artisan config:cache
php artisan optimize:clear

touch /app/storage/framework/sessions/r9yIHf3WlKIzROWGPlVOk59rwr6tVyAeCLuJ9wWx也不起作用.

我试图删除存储文件夹并重新创建.

I've tried to remove the storage folder and create it again.

您有什么可能出问题的主意吗?

Do you have an idea of what could go wrong?

推荐答案

Heroku的文件系统是临时的,并且在您的dynos重新启动时会消失-即每天至少一次(由于Heroku会自动重新启动)以及每次部署之后或配置更改.

Heroku's filesystem is temporary, and goes away any time your dynos are restarted - i.e. at least once daily (due to the automatic restarts Heroku does) and after every deploy or config change.

此外,heroku run bash将您连接到全新的独立服务器,因此,如果您要在其中创建/修改文件/文件夹/权限,它将完全消失.当您关闭会话时.对实际的Web服务器实例没有任何影响.

In addition, heroku run bash connects you to a brand new, separate server, so if you're creating/modifying files/folders/permissions in that, it'll literally all go away as soon as you close out of the session. There's no effect on the actual webserver instances.

这意味着您不应该依赖文件系统来实现任何永久性的操作,例如,不上传文件(它们应位于类似于AWS S3的地方).另外,如果您使用多个dyno,则将会话数据存储为文件将意味着该会话仅存在于一个dyno中-在下一次网页浏览时,很有可能它会消失,因为用户点击了不同 dyno.

This means you shouldn't rely on the filesystem for anything intended to be permanent - no file uploads, for example (they should go somewhere like AWS S3). Plus, if you're using more than one dyno, storing session data as files will mean the session only exists on one of the dynos - on the next pageview, there's a good chance it'll be gone, as the user has hit a different dyno.

解决方案?使用其他驱动程序存储会话.我更喜欢Redis驱动程序,但是如果您想降低复杂性,则可以使用数据库驱动程序.

Solution? Store sessions using a different driver. I prefer the Redis driver, but you could use the database one if you wanted to keep complexity down a bit.

这篇关于Laravel/Heroku,没有用于会话的此类文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆