php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75946 session_start() fails after fastcgi_finish_request() (FPM)
Submitted: 2018-02-10 09:11 UTC Modified: 2018-02-11 13:36 UTC
From: rafal dot janiczek at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Session related
PHP Version: 7.1.14 OS: Linux
Private report: No CVE-ID: None
 [2018-02-10 09:11 UTC] rafal dot janiczek at gmail dot com
Description:
------------
Not affected: php 7.0.x 

Affected: php7.1.x (tested .14) and php7.2.x (tested .2)



Test script:
---------------
<?php

session_start();

echo session_id()."\n";
$_SESSION['test'] = 1;

echo "stop session\n";
session_write_close();

fastcgi_finish_request();

session_start();
$_SESSION['test'] = 2;
session_write_close();


$status = session_start();

if ($status)
    file_put_contents("sesstest.log", date("Y-m-d")." OK ".$_SESSION['test']." ".session_id());
else
    file_put_contents("sesstest.log", date("Y-m-d")." ERR ".$_SESSION['test']." ".session_id());




Expected result:
----------------
string "OK 2" in sesstest.log


Actual result:
--------------
string "ERR 1" in sesstest.log

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-10 09:57 UTC] spam2 at rhsoft dot net
this is not a bug! you can't start a session after data was sent to the client which happens with fastcgi_finish_request() as "This function flushes all response data to the client and finishes the request. This allows for time consuming tasks to be performed without leaving the connection to the client open" clearly states

why do you believe that this piece of code ever did what you think?

the only difference is that PHP now tells you that your code is and was always broken and thinking abotu what session_start() does - sending a HTTP header - that becomes obvious
 [2018-02-10 11:10 UTC] rafal dot janiczek at gmail dot com
You'are right, it's bad code, but this piece of code was working since php-5.5.21(first time) and checking on 3v4l it was working since 4.3.x. Of course always with warning (headers already sent), but was working. Now it's problem with php 7.1 and 7.2. For me it's bug or regression. 

Maybe it's good to inform about that on http://php.net/manual/en/function.session-start.php ? There is nothing about that change in >7.1 series.

https://3v4l.org/A06Gr
 [2018-02-10 13:38 UTC] spam2 at rhsoft dot net
jesus christ when you get a warning "headers already sent" it did NOT work because the whole purpose of session_start() is send the PHPSESSID cookie to the client

again: you thought it worked but it never did and now you get the truth additional to the warning - so say thank you that a major bug was fixed and points out broken code you never realized how broken it is
 [2018-02-10 15:33 UTC] rafal dot janiczek at gmail dot com
-Type: Bug +Type: Documentation Problem
 [2018-02-10 15:33 UTC] rafal dot janiczek at gmail dot com
Ok, propoably this report is related with #71038.

But if it was major fix for sessions why there's no any info on session_start page or "PHP 7.1.0 Release Announcement" or "Backward incompatible changes"? 

Please just write it in changelog box for session_start().
 [2018-02-11 13:14 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2018-02-11 13:14 UTC] cmb@php.net
Indeed, even though there is an explicit mention in UPGRADING[1],
this wasn't incorporated in the changelog.

[1] <https://github.com/php/php-src/blob/PHP-7.1.0/UPGRADING#L136-L137>
 [2018-02-11 13:36 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=344212
Log: Fix bug #75946 (session_start() fails after fastcgi_finish_request() (FPM))
 [2018-02-11 13:36 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2018-02-11 13:36 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:05 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=ef9b464ad778b0e470d536c1e4a2a011f203e165
Log: Fix bug #75946 (session_start() fails after fastcgi_finish_request() (FPM))
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 20:01:29 2024 UTC