|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77588 Session started with read_and_close creates empty session
Submitted: 2019-02-08 13:38 UTC Modified: 2019-02-17 04:22 UTC
From: piotr at halas dot net dot pl Assigned:
Status: No Feedback Package: Session related
PHP Version: 7.2.15 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-02-08 13:38 UTC] piotr at halas dot net dot pl
I don't know if this is a bug, but when starting a session with read_and_close options enabled PHP creates an empty session if no session was found. 

Test script:
ini_set('session.save_path', getcwd());
session_start(['read_and_close' => true]);
echo "Sessions: ".count(glob(getcwd().'/sess_*')).PHP_EOL;

Expected result:
Sessions: 0

Actual result:
Sessions: 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-08 13:44 UTC] spam2 at rhsoft dot net
what does the ini_set here and are you aware that it is not supposed to init a new session but resume one readonly to watch for example status of file uploads
 [2019-02-08 13:53 UTC] piotr at halas dot net dot pl
Ini_set is only for test purpose. 
The problem is that session_start(['read_and_close' => true]) creates new empty session file if no session file is found. This happens also with memcached save_handler.
 [2019-02-08 14:02 UTC] spam2 at rhsoft dot net
hell you use a readonly option and ask why it don't write...
 [2019-02-08 14:14 UTC] sjon at hortensius dot net
I don't think this is a bug - all read_and_close does is "result in the session being closed immediately after being read"
so it doesn't influence session_start from creating an empty session like it always does - see
 [2019-02-09 00:40 UTC]
-Status: Open +Status: Feedback
 [2019-02-09 00:40 UTC]
I got this result from my Fedora's PHP 7.2.14.
Are you using "files" save handler? I guess not.

It looks like I have to document "save handler" authors must create session data (and lock it) upon read when data does not exist yet.

[yohgaki@dev PHP-master]$ php -v
PHP 7.2.14 (cli) (built: Jan  8 2019 09:59:17) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.14, Copyright (c) 1999-2018, by Zend Technologies
[yohgaki@dev PHP-master]$ php 
ini_set('session.save_path', getcwd());
session_start(['read_and_close' => true]);
echo "Sessions: ".count(glob(getcwd().'/sess_*')).PHP_EOL;

Sessions: 1
 [2019-02-09 00:43 UTC]
The same result with current master as expected.

[yohgaki@dev PHP-master]$ ./sapi/cli/php -v
PHP 8.0.0-dev (cli) (built: Feb  9 2019 09:39:31) ( NTS DEBUG )
 [2019-02-17 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 15:01:29 2024 UTC