laravel 如何从laravel中的所有服务器会话中获取列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15977024/
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-09-14 07:42:09  来源:igfitidea点击:

How to get a list off all server sessions in laravel?

phpsessionframeworkslaravel

提问by Ehsan Zargar Ershadi

I'm using Laravel 3. I want to know how many users are online , so i thought i might count all server sessions. dose any one know how i could do this? Note : I'm using 'driver' => 'file',in the session configuration.

我正在使用 Laravel 3。我想知道有多少用户在线,所以我想我可以计算所有服务器会话。有人知道我怎么做吗?注意:我'driver' => 'file',在会话配置中使用。

采纳答案by Pratheek Rebala

You can configure sessions class to use a database to store session data, then you can query the sessions table to perform your queries, this is a feature in Laravel itself.

你可以配置 session 类来使用数据库来存储 session 数据,然后你可以查询 session 表来执行你的查询,这是 Laravel 本身的一个特性。

The exact method of configuring sessions will vary by the type of DB you are using, here's a guide to setting up sessions using databases: http://laravel.com/docs/session/config#database

配置会话的确切方法因您使用的数据库类型而异,这里是使用数据库设置会话的指南:http: //laravel.com/docs/session/config#database

回答by Invincible

This worked for me.

这对我有用。

Session::instance()->session['data'];