php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53754 Modify headers_list() to return an array of set headers in CLI SAPI
Submitted: 2011-01-14 22:45 UTC Modified: 2012-05-13 07:52 UTC
Votes:9
Avg. Score:4.4 ± 0.7
Reproduced:9 of 9 (100.0%)
Same Version:5 (55.6%)
Same OS:4 (44.4%)
From: pistole at rhp dot org Assigned:
Status: Wont fix Package: CGI/CLI related
PHP Version: 5.3.5 OS: Ubuntu Server 10.0
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pistole at rhp dot org
New email:
PHP Version: OS:

 

 [2011-01-14 22:45 UTC] pistole at rhp dot org
Description:
------------
Calling headers_list() from the CLI version of PHP always returns an empty array, ignoring the results of previous calls to header(), despite the fact that they are already tracked internally.

As some background, I'm attempting to write a pure PHP bootstrap development HTTP server to help programmers easily create new development environments and for lightweight standalone webapps that don't need a fully featured web-server to deploy.

One of the things I'm trying to accomplish with this is to enable out of the box usage on various *nix distros and Mac OSX. The PHP-CGI SAPI is perfect for my project, but it isn't always installed by default (certainly not on OSX), so I'm attempting to make it work with the CLI version.

I've managed to work around most of the limitations I've run up against, but this headers_list() always returning an empty array is a complete show-stopper. Without being able to retrieve the list, apps that set any kind of custom headers (including cookies), can never work correctly.

I've attached a one-line patch to enable headers_list() to function in the CLI SAPI. Another (probably better) option would be to create an ini file setting to determine which behavior to exhibit. I'd be happy to do the dev work for that and submit the revised patch.


Test script:
---------------
#!/usr/bin/php
<?php
header('Location: asdf');
$list = headers_list();
var_dump($list);

Expected result:
----------------
array(2) {
  [0]=>
  string(23) "X-Powered-By: PHP/5.3.5"
  [1]=>
  string(14) "Location: asdf"
}


Actual result:
--------------
array(0) {
}


Patches

php_cli-headers_list.patch (last revision 2011-01-14 21:46 UTC by pistole at rhp dot org)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-06 00:18 UTC] wiltave at gmail dot com
It would be useful to write unit tests. Some codes need to send headers.
Thank you.
 [2012-05-13 07:52 UTC] stas@php.net
-Status: Open +Status: Wont fix
 [2012-05-13 07:52 UTC] stas@php.net
CLI is not meant to work with HTTP headers, that's what CGI one is for.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 20:01:29 2024 UTC