php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73936 Certain special header() calls wrongly prevent connection from closing
Submitted: 2017-01-14 18:38 UTC Modified: -
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: markamery at btinternet dot com Assigned:
Status: Open Package: Apache2 related
PHP Version: Irrelevant OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
17 - 6 = ?
Subscribe to this entry?

 
 [2017-01-14 18:38 UTC] markamery at btinternet dot com
Description:
------------
Running under mod_php, calling

    header('HTTP/1.1 200 OK');

seems to prevent the connection from being closed once the PHP script finishes. This can be demonstrated by, for instance, hitting the script with ab (the Apache benchmark tool), which (unlike most HTTP clients, including browsers) only considers a request to have finished once the connection is closed, rather than when Content-Length bytes have been received. http://stackoverflow.com/q/34367115/1709587 describes this case in more detail.

Bizarrely,

    header('http/1.1 200 OK');

does not have the same effect, despite producing a character-for-character identical HTTP response (as can be observed with `curl -i --raw`).

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

header('HTTP/1.1 200 OK');


Expected result:
----------------
Unless `Connection: keep-alive` is specified in the request, the connection should close once the PHP script finishes. In particular, the behaviour should be identical to other calls with the same meaning, like

    <?php
    
        http_response_code(200);

or

    <?php

        header('http/1.1 200 OK')

Actual result:
--------------
The connection does not close, and the alternate scripts suggested above have different behaviours to the test script.

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Apr 02 09:01:22 2020 UTC