php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74185 PHP periodically failing to populate superglobals
Submitted: 2017-02-28 18:09 UTC Modified: 2017-09-12 18:31 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: robin at willowsv dot com Assigned: ab (profile)
Status: Closed Package: Variables related
PHP Version: 7.1.2 OS: Windows 7
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 !
Your email address:
MUST BE VALID
Solve the problem:
28 + 44 = ?
Subscribe to this entry?

 
 [2017-02-28 18:09 UTC] robin at willowsv dot com
Description:
------------
Periodically PHP will periodically fail to populate the $_COOKIE Super global.

The logs will report that _COOKIE is undefined if you check it (depending on the reporting level) and if it's set first it will behave like a non superglobal with normal variable scope. 

A restart of the Apache/PHP server corrects the issue however it hits sporadically and refused to allow us to sign in. $_SERVER reports cookie data is available.

Test script:
---------------
<?php
	
	echo("Dumping Server!\n");	print_r($_SERVER);
	echo("\n\nDumping Cookie!\n");	print_r($_COOKIE);
	
	// Set Value
	echo("\n\nSetting Cookie!\n");	$_COOKIE['TEST'] = "TEST";
	print_r($_COOKIE);
	
	// Echo
	echo("\n\nTest 1!\n");		test();
	echo("\n\nTest 2!\n");		test2();
	
	// Test Function 1 (No Global)
	function test() {
		if ( empty($_COOKIE) )
			echo("Can't find cookie superglobal!\n");
		}
		else {
			echo("Dumping Cookie!\n");
			print_r($_COOKIE);
		}
	}
	
	// Test Function 2 (No Global)
	function test2() {
		global $_COOKIE;
		if ( empty($_COOKIE) ) {
			echo("Can't find cookie superglobal!");
		}
		else {
			echo("Dumping Cookie!\n");
			print_r($_COOKIE);
		}
	}
	
?>

Expected result:
----------------
Dumping Server!
Array
(
    [HTTPS] => on
    [SSL_SESSION_RESUMED] => Initial
    [HTTP_HOST] => 10.224.130.232
    [HTTP_CONNECTION] => keep-alive
    [HTTP_CACHE_CONTROL] => max-age=0
    [HTTP_UPGRADE_INSECURE_REQUESTS] => 1
    [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    [HTTP_ACCEPT_ENCODING] => gzip, deflate, sdch, br
    [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8,en-GB;q=0.6
    [HTTP_COOKIE] => CMS=18368a69a2b9b1d7a62918213adcf19d; SVMCMS=05bfdca9adaf72b52578668069db639f61652476; PHPSESSID=1b86072d4b839507ae6e7223f3645923
    [SystemRoot] => C:\Windows
    [COMSPEC] => C:\Windows\system32\cmd.exe
    [WINDIR] => C:\Windows
    [SERVER_SIGNATURE] => 
    [SERVER_SOFTWARE] => Apache/2.4.25 (Win32) OpenSSL/1.0.2k PHP/7.1.2
    [SERVER_PORT] => 443
    [DOCUMENT_ROOT] => D:/www/httpdocs
    [REQUEST_SCHEME] => https
    [CONTEXT_PREFIX] => 
    [CONTEXT_DOCUMENT_ROOT] => D:/www/httpdocs
    [SERVER_ADMIN] => admin@example.com
    [SCRIPT_FILENAME] => D:/www/httpdocs/cms/bug.php
    [REMOTE_PORT] => 62749
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => 
    [REQUEST_URI] => /cms/bug.php
    [SCRIPT_NAME] => /cms/bug.php
    [PHP_SELF] => /cms/bug.php
    [REQUEST_TIME_FLOAT] => 1488303793.707
    [REQUEST_TIME] => 1488303793
    [argv] => Array
        (
        )

    [argc] => 0
)


Dumping Cookie!
Array
(
    [CMS] => 18368a69a2b9b1d7a62918213adcf19d
    [SVMCMS] => 05bfdca9adaf72b52578668069db639f61652476
    [PHPSESSID] => 1b86072d4b839507ae6e7223f3645923
)


Setting Cookie!
Array
(
    [CMS] => 18368a69a2b9b1d7a62918213adcf19d
    [SVMCMS] => 05bfdca9adaf72b52578668069db639f61652476
    [PHPSESSID] => 1b86072d4b839507ae6e7223f3645923
    [TEST] => TEST
)


Test 1!
Dumping Cookie!
Array
(
    [CMS] => 18368a69a2b9b1d7a62918213adcf19d
    [SVMCMS] => 05bfdca9adaf72b52578668069db639f61652476
    [PHPSESSID] => 1b86072d4b839507ae6e7223f3645923
    [TEST] => TEST
)


Test 2!
Dumping Cookie!
Array
(
    [CMS] => 18368a69a2b9b1d7a62918213adcf19d
    [SVMCMS] => 05bfdca9adaf72b52578668069db639f61652476
    [PHPSESSID] => 1b86072d4b839507ae6e7223f3645923
    [TEST] => TEST
)

Actual result:
--------------
Dumping Server!
Array
(
    [HTTPS] => on
    [SSL_SESSION_RESUMED] => Resumed
    [HTTP_HOST] => 10.224.130.232
    [HTTP_CONNECTION] => keep-alive
    [HTTP_CACHE_CONTROL] => max-age=0
    [HTTP_UPGRADE_INSECURE_REQUESTS] => 1
    [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
    [HTTP_ACCEPT_ENCODING] => gzip, deflate, sdch, br
    [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8,en-GB;q=0.6
    [HTTP_COOKIE] => CMS=18368a69a2b9b1d7a62918213adcf19d; SVMCMS=05bfdca9adaf72b52578668069db639f61652476; PHPSESSID=1b86072d4b839507ae6e7223f3645923
    [SystemRoot] => C:\Windows
    [WINDIR] => C:\Windows
    [SERVER_SIGNATURE] => 
    [SERVER_SOFTWARE] => Apache/2.4.25 (Win32) OpenSSL/1.0.2k PHP/7.1.2
    [SERVER_PORT] => 443
    [DOCUMENT_ROOT] => D:/www/httpdocs
    [REQUEST_SCHEME] => https
    [CONTEXT_PREFIX] => 
    [CONTEXT_DOCUMENT_ROOT] => D:/www/httpdocs
    [SERVER_ADMIN] => admin@example.com
    [SCRIPT_FILENAME] => D:/www/httpdocs/cms/bug.php
    [REMOTE_PORT] => 62746
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => 
    [REQUEST_URI] => /cms/bug.php
    [SCRIPT_NAME] => /cms/bug.php
    [PHP_SELF] => /cms/bug.php
    [REQUEST_TIME_FLOAT] => 1488303761.429
    [REQUEST_TIME] => 1488303761
    [argv] => Array
        (
        )

    [argc] => 0
)


Dumping Cookie!


Setting Cookie!
Array
(
    [TEST] => TEST
)


Test 1!
Can't find cookie superglobal!


Test 2!
Dumping Cookie!
Array
(
    [TEST] => TEST
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-28 18:16 UTC] robin at willowsv dot com
Not just $_COOKIE either

Severity: Notice --> Undefined variable: _GET D:\www\httpdocs\cms\system\core\Input.php 609
 [2017-02-28 18:21 UTC] spam2 at rhsoft dot net
sounds like a bug in http://php.net/manual/en/ini.core.php#ini.auto-globals-jit on windows and maybe related to bytecode cache - dunno if windows these days also is using opcache, but you can try "auto_globals_jit = 0" and 0/1 in combination with and without bytecode-caching
 [2017-03-02 17:52 UTC] robin at willowsv dot com
Already tried playing with the JIT value.

Don't seem to have an option for bytecode-caching.
 [2017-03-02 18:38 UTC] spam2 at rhsoft dot net
no idea what you try to tell me with "Don't seem to have an option for bytecode-caching" - nobody but you knows how your sevrer is configured and if it is using "opcache" or "wincache" or whatever is available for the redmond-gameloader - consult your phpinfo() output
 [2017-03-29 12:13 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2017-03-29 12:13 UTC] ab@php.net
Please try using this snapshot:

  http://snaps.php.net/php-trunk-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2017-03-29 18:09 UTC] ab@php.net
-Status: Feedback +Status: Closed -Assigned To: +Assigned To: ab
 [2017-03-29 18:09 UTC] ab@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

can actually be closed, fixed in master.

Thanks.
 [2017-03-31 10:49 UTC] robin at willowsv dot com
No Joy :(

System	Windows NT PC 6.1 build 7601 (Windows 7 Professional Edition Service Pack 1) i586
Build Date	Mar 30 2017 15:32:03
Compiler	MSVC14 (Visual C++ 2015)
Architecture	x86

Apache/2.4.25 (Win32) OpenSSL/1.0.2k PHP/7.1.5-dev



ERROR - 2017-03-31 03:34:47 --> Severity: Notice --> Undefined variable: _GET D:\www\httpdocs\cms\system\core\Input.php 609
ERROR - 2017-03-31 03:34:47 --> Severity: Notice --> Undefined variable: _SERVER D:\www\httpdocs\cms\system\core\Input.php 654
ERROR - 2017-03-31 03:34:47 --> Severity: Notice --> Undefined variable: _SERVER D:\www\httpdocs\cms\application\config\config.php 27
ERROR - 2017-03-31 03:34:47 --> Severity: Notice --> Undefined variable: _SERVER D:\www\httpdocs\cms\application\config\config.php 27
ERROR - 2017-03-31 03:34:47 --> Severity: Notice --> Undefined variable: _SERVER D:\www\httpdocs\cms\application\config\config.php 27
ERROR - 2017-03-31 03:34:47 --> Severity: Notice --> Undefined variable: _GET D:\www\httpdocs\cms\system\core\Input.php 609
ERROR - 2017-03-31 03:34:47 --> Severity: Notice --> Undefined variable: _SERVER D:\www\httpdocs\cms\system\core\Input.php 654
ERROR - 2017-03-31 03:34:47 --> Severity: Notice --> Undefined variable: _GET D:\www\httpdocs\cms\system\core\Input.php 609
ERROR - 2017-03-31 03:34:47 --> Severity: Notice --> Undefined variable: _GET D:\www\httpdocs\cms\system\core\Input.php 609
ERROR - 2017-03-31 03:34:47 --> Severity: Notice --> Undefined variable: _SERVER D:\www\httpdocs\cms\system\core\Input.php 654
ERROR - 2017-03-31 03:34:47 --> Severity: Notice --> Undefined variable: _SERVER D:\www\httpdocs\cms\system\core\Input.php 654
 [2017-03-31 10:54 UTC] nikic@php.net
To clarify, ab is referring to master snapshots (at the very bottom of http://windows.php.net/snapshots/), while you are testing a PHP 7.1 snapshot. The fix for this issue is involved and ABI breaking, so it will not go into 7.1.
 [2017-03-31 11:04 UTC] ab@php.net
Yeah, more precisely http://windows.php.net/downloads/snaps/master/r6574d9f/ or any other vc14 snap after March 10th. Please don't take the latest vc15 snaps, as they depend on OpenSSL 1.1 which will conflict with 1.0 contained in older httpd builds.

Thanks.
 [2017-03-31 11:12 UTC] robin at willowsv dot com
I see

Now on php-master-ts-windows-vc14-x86-r6574d9f.zip

Reported as 7.2.0-dev
 [2017-09-12 02:30 UTC] jamwhitl at cisco dot com
This also happens on $_REQUEST on all versions of PHP7.  I’ve been experiencing this problem since 7 came out.  I’m still using 5.6.29 because of it.  Windows server 2008 R2 with Apache 2.4.25/27.
 [2017-09-12 17:08 UTC] a dot gurevicius at gmail dot com
So, has this been fixed in any php 7 version? I've just got the same problem on Windows php 7.1.8. The $_GET superglobal is NULL, while $_REQUEST is ok. Restarting Apache solved the problem, but it keeps coming back. Is there anything that can be done?
 [2017-09-12 17:38 UTC] ab@php.net
It is fixed in 7.2. It would be great the pre releases could be tested therefore.

Thanks.
 [2017-09-12 18:19 UTC] jamwhitl at cisco dot com
It's not fixed.  I've have 7.1.8 on two development servers and a production sever.  The problem is random with, anywhere from 2 hours to a week after apache is restarted. Extensive testing has indicated the problem is with other superglobals like $_POST and $_SESSION as well.  Restating Apache always resolves it, but that's not an acceptable solution in a production environment.  I think this bug should be reopened, or at least a new one opened.
 [2017-09-12 18:31 UTC] ab@php.net
@jamwhitl please fetch any PHP 7.2 pre here http://windows.php.net/qa/ , or any latest 7.2 snapshot. Mentioned above, but just to be clear - this fix is not present and won't be in PHP 7.1 and lower.

Thanks.
 [2017-09-12 18:34 UTC] spam2 at rhsoft dot net
when someone tells you "It is fixed in 7.2" your response "It's not fixed. I've have 7.1.8" is just nonsense (even if we ignore that 7.1.8 is *not* the current bugfix release because PHP 7.1.9 built: Aug 31 2017 15:38:22)
 [2017-09-12 18:58 UTC] jamwhitl at cisco dot com
My mistake, I got hung up on the wrong version. I'll try the 7.2 release.
 [2017-09-24 17:22 UTC] a dot gurevicius at gmail dot com
I've just updated our server to 7.2.0 RC2. This version should have the problem fixed, as I understand, correct? Will let you know if it helped.
 [2017-10-05 08:40 UTC] a dot gurevicius at gmail dot com
It's been almost two weeks and I am happy to report, that there has been no crashes on 7.2.0 RC2. So the fix works.
 [2017-11-06 11:05 UTC] ca at lsp dot net
We noticed that the

  Undefined variable: _GET

errors in our PHP 7.0.21 error log were preceded by

  Can't initialize heap: [0x000001e7] Attempt to access invalid address.

errors in our Apache 2.4.28 error log.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 10:01:29 2024 UTC