php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63106 get_headers( ) loops on localhost
Submitted: 2012-09-18 07:29 UTC Modified: 2012-09-18 14:20 UTC
From: valentiny510 at yahoo dot es Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.4.7 OS: Windows XP
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: valentiny510 at yahoo dot es
New email:
PHP Version: OS:

 

 [2012-09-18 07:29 UTC] valentiny510 at yahoo dot es
Description:
------------
First I want to say I have an offer of 2x1 bugs. I will start with a bit of history.. (for some reason) I have a test server added to my system32/drivers/etc/hosts. Ex: 127.0.0.1 testserver.com
and I thought the problem can be the name of something like that, and deletind the line doesn't solve the problem, and then I realized that the problem is the function inself with the localhost.
Is almost understandable becouse it try to get the self headers over and over again. Almost like: function get($headers){return get($headers);}
The subsequent problem is that is bypassing the time limit of the script, 30 seconds (or whatever time limit is) and the script when reach the limit, the limit is restarted and run again for few minutes 'till the browser stop it.
The error.log will have thousands of line with the error limit..
The documentation doesn't say nothing about localhost.

Speaking of error log, here come the second bug. NOTE: only happens with the bug above ! That why I put together. Ok.. lets see..
For production (like almost everybody, i guess) I use:
ini_set('log_errors', false);
ini_set('display_errors', false);
Ok.. When I try to see the error returned by the above bug with "display_error true", nothing is showed, and ONLY when "log_errors are true" it show me the error "Time limit 30 seconds etc...", also it show me the error with "display_errors false" too ! Something strange there..
Maybe is becouse the script running foreaver, when the browser it stop it, the php does have nothing "prepared" to show.. and must get something from the error.log to display something to the browser

To finish, maybe the second is the subsequent of the first bug (almost sure it is), so dont give to mush importance to that, and fix just the first one.


Test script:
---------------
<?php
var_dump(get_headers('http://localhost'));

Expected result:
----------------
The list of all headers..
or some error like "The php can not get the headers from localhohst" :D

Actual result:
--------------
The script run forever and ever.. (what a happy ending) ..'till the browser dies.. (what a sad ending)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-18 08:28 UTC] laruence@php.net
I don't understand what's bug do you mean?

recursive calling getheaders obviously will result a infinite loop.
 [2012-09-18 09:00 UTC] valentiny510 at yahoo dot es
I would espect at least something like var_export( $GLOBALS );
"Nesting level too deep - recursive dependency?"
 [2012-09-18 10:30 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2012-09-18 10:30 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

no, because the recursive is not predictable for PHP, 

get_headers will send a request to the target url, and get the response,

in your test, the target is the script self, then it call get_headers again and 
agian.
 [2012-09-18 12:04 UTC] valentiny510 at yahoo dot es
Is not "predictable" ? What about some static variable or something like this ?
(pseudofunction)
function get_headers( url )
{
    server_from_where_script_is_called = $_SERVER['host'];
    if ( url == same_server )
        error('Cannot get the headers from the same domain bla bla bla');
    else
        // do normal stuff ...
}
What about traspassing the script time limit ?
 [2012-09-18 14:20 UTC] laruence@php.net
they are even not in the same process..
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 19:01:31 2024 UTC