gpt4 book ai didi

PHP session 启动打开文件而不是数据库连接

转载 作者:行者123 更新时间:2023-11-29 18:09:04 25 4
gpt4 key购买 nike

经过几天的研究,我刚刚注意到下面的错误消息中的路径看起来很奇怪。

打开(/var/lib/php/session/sess_fvc591eu71mbrc4tabgtr83pg7,O_RDWR)失败:

有两件事让我觉得很奇怪。

  1. 目标似乎是/var/lib/php/下的目录,对于脚本创建输出文件来说,这似乎是一个非常奇怪的地方。
  2. 该脚本应该将其 session 数据存储在 MySQL 数据库中。

以下是压缩的堆栈跟踪。

1/1) ErrorException
session_start():
open(/var/lib/php/session/sess_fvc591eu71mbrc4tabgtr83pg7,
O_RDWR) failed: No such file or directory (2)

in Session.php (line 40)
at HandleExceptions->handleError(2, 'session_start():
open(/var/lib/php/session/sess_fvc591eu71mbrc4tabgtr83pg7,
O_RDWR)
failed: No such file or directory (2)',
'/var/www/praesidium/pch/vendor/
lusitanian/oauth/src/OAuth/Common/Storage/Session.php',
40, array('startSession' => true,
'sessionVariableName' => 'lusitanian-oauth-token',
'stateVariableName' => 'lusitanian-oauth-state'))
at session_start()

in Session.php (line 40)
at Session->__construct()

in OAuth.php (line 101)
at OAuth->createStorageInstance('\\OAuth\\Common\\Storage\\Session')

in OAuth.php (line 132)
at OAuth->consumer('Salesforce')

in Facade.php (line 221)
at Facade::__callStatic('consumer', array('Salesforce'))

in PCHPageController.php (line 130)
$oSFOAuthService = \OAuth::consumer ( 'Salesforce' );
at OAuth::consumer('Salesforce')
in PCHPageController.php (line 130)
at PCHPageController->ShowPageLogin()
at call_user_func_array(array(
object(PCHPageController), 'ShowPageLogin'), array())
in Controller.php (line 55)

以下是环境数组中的关键项,取自本地 XDebug session 。

$_ENV                       Array [24]
[DB_CONNECTION] "mysql"
[SESSION_DRIVER] "database"
[DB_CONNECTION] "mysql"

该应用程序在 PHP 5.6.32 上使用 LARAVEL 5 框架,在 Amazon Linux 实例中运行,并且 session 由 LARAVEL 的 LUSITANIAN OAUTH 模块管理,我怀疑该模块忽略了环境中的 session 设置。

以下是我的整个 session 配置文件。

return [

/*
|------------------------------------------------------------------------
| Default Session Driver
|------------------------------------------------------------------------
|
| This option controls the default session "driver" that will be used on
| requests. By default, we will use the lightweight native driver but
| you may specify any of the other wonderful drivers provided here.
|
| Supported: "file", "cookie", "database", "apc",
| "memcached", "redis", "array"
|
*/

'driver' => env ( 'SESSION_DRIVER' , 'database' ) ,

/*
|------------------------------------------------------------------------
| Session Lifetime
|------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/

'lifetime' => 120,

'expire_on_close' => false,

/*
|------------------------------------------------------------------------
| Session Encryption
|------------------------------------------------------------------------
|
| This option allows you to easily specify that all of your session data
| should be encrypted before it is stored. All encryption will be run
| automatically by Laravel and you can use the Session like normal.
|
*/

'encrypt' => false,

/*
|------------------------------------------------------------------------
| Session File Location
|------------------------------------------------------------------------
|
| When using the native session driver, we need a location where session
| files may be stored. A default has been set for you but a different
| location may be specified. This is only needed for file sessions.
|
*/

'files' => storage_path('framework/sessions'),

/*
|------------------------------------------------------------------------
| Session Database Connection
|------------------------------------------------------------------------
|
| When using the "database" or "redis" session drivers, you may specify a
| connection that should be used to manage these sessions. This should
| correspond to a connection in your database configuration options.
|
*/

'connection' => 'mysql',

/*
|------------------------------------------------------------------------
| Session Database Table
|------------------------------------------------------------------------
|
| When using the "database" session driver, you may specify the table we
| should use to manage the sessions. Of course, a sensible default is
| provided for you; however, you are free to change this as needed.
|
*/

'table' => 'sessions',

/*
|------------------------------------------------------------------------
| Session Cache Store
|------------------------------------------------------------------------
|
| When using the "apc" or "memcached" session drivers, you may specify a
| cache store that should be used for these sessions. This value must
| correspond with one of the application's configured cache stores.
|
*/

'store' => null,

/*
|------------------------------------------------------------------------
| Session Sweeping Lottery
|------------------------------------------------------------------------
|
| Some session drivers must manually sweep their storage location to get
| rid of old sessions from storage. Here are the chances that it will
| happen on a given request. By default, the odds are 2 out of 100.
|
*/

'lottery' => [2, 100],

/*
|------------------------------------------------------------------------
| Session Cookie Name
|------------------------------------------------------------------------
|
| Here you may change the name of the cookie used to identify a session
| instance by ID. The name specified here will get used every time a
| new session cookie is created by the framework for every driver.
|
*/

'cookie' => 'laravel_session',

/*
|------------------------------------------------------------------------
| Session Cookie Path
|------------------------------------------------------------------------
|
| The session cookie path determines the path for which the cookie will
| be regarded as available. Typically, this will be the root path of
| your application but you are free to change this when necessary.
|
*/

'path' => '/',

/*
|------------------------------------------------------------------------
| Session Cookie Domain
|------------------------------------------------------------------------
|
| Here you may change the domain of the cookie used to identify a session
| in your application. This will determine which domains the cookie is
| available to in your application. A sensible default has been set.
|
*/

'domain' => env('SESSION_DOMAIN', null),

/*
|------------------------------------------------------------------------
| HTTPS Only Cookies
|------------------------------------------------------------------------
|
| By setting this option to true, session cookies will only be sent back
| to the server if the browser has a HTTPS connection. This will keep
| the cookie from being sent to you if it can not be done securely.
|
*/

'secure' => env('SESSION_SECURE_COOKIE', true),

/*
|------------------------------------------------------------------------
| HTTP Access Only
|------------------------------------------------------------------------
|
| Setting this value to true will prevent JavaScript from accessing the
| value of the cookie and the cookie will only be accessible through
| the HTTP protocol. You are free to modify this option if needed.
|
*/

'http_only' => true,

];

所有调用频率都是开放的。

最佳答案

简短的回答是,我们发现相关库硬连接到内部 PHP Session 对象,该对象似乎仅限于使用文件系统作为其后备存储。此后,我们放弃了该库,并正在为 PHP League 的 OAuth2 库实现 Stephen Maguire 的专用 Salesforce 提供商。

关于PHP session 启动打开文件而不是数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47548555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com