php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61332 WinCache Session don't save an array if element count not changed just a value
Submitted: 2012-03-09 00:32 UTC Modified: 2015-08-27 22:30 UTC
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: haliferi at freemail dot hu Assigned: ericsten (profile)
Status: Closed Package: WinCache (PECL)
PHP Version: 5.3.10 OS: Windows Server 2008 R2
Private report: No CVE-ID: None
 [2012-03-09 00:32 UTC] haliferi at freemail dot hu
Description:
------------
I am running PHP 5.3.10 x86 (API220090626,NTS,VC9) on IIS7.5 with Wincache Version 1.1.0630.0, opcode cache enabled, session works in all other cases.

I have an array in the session, but if i unset the first item, and add a new to the and, then Wincache won't save it to the session in my case. But if i modify the item count: unset the first 2 element, then it will be saved. The other session variables are not affected, objects, ints are successfully saved to the session.

I tested it with WinCache 1.2.427, 1.2.614 and 1.2.1208 too, but nothing changed.

Test script:
---------------
$_SESSION['chresp'] = array( // already saved in the session
'dfjkg6' => 
array('a' => 'gdfg7df887', 'b' => 'h34g3436sh', 'valid' => 1331196464),
'5gf5av' => 
array('a' => 'tu4dcff3d3', 'b' => 'gh323fghd3', 'valid' => 1331196465),
's7g35b' => 
array('a' => '32a4djg2sa', 'b' => 'ib78m37fdj', 'valid' => 1331196466));


if (count($_SESSION['chresp']) > 2)
  array_shift($_SESSION['chresp']);

$_SESSION['chresp']['kjhg7f'] =
  array('a' => 'kgkj3dfkg7', 'b' => 'as88f4jk4jk', 'valid' => 1331196467);

// i can see the new value here, but the next refresh the init array appears again

Expected result:
----------------
The new array has saved to the session.

Actual result:
--------------
If i run the test script standalone, it works, but as i run it in my project, it produces the bug, maybe another session, or wincache user cache reads/writes have makes this effect together.

But if i switch to any other session handler in the php.ini (memcache, simple file), it solves the problem.

The most weird is that modifying the element count makes Wincache to save it.

There is no error, warning, everything is in order, just the array won't be updated in the wincache session store.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-20 16:30 UTC] ericsten@php.net
-Assigned To: +Assigned To: ericsten
 [2015-08-27 22:30 UTC] ericsten@php.net
-Status: Assigned +Status: Closed
 [2015-08-27 22:30 UTC] ericsten@php.net
I wrote a script to simulate this issue with the session array and tested it with PHP7 + WinCache 2.0.0.0 on x64.  I was unable to repro the issue.

Test Script:
------------
<?php

function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $randomString;
}

session_start();

$sess_data = $_SESSION['chresp'];

if (NULL == $sess_data)
{
  $sess_data = array( 
    'dfjkg6' => 
       array('a' => 'gdfg7df887', 'b' => 'h34g3436sh', 'valid' => 1331196464),
    '5gf5av' => 
      array('a' => 'tu4dcff3d3', 'b' => 'gh323fghd3', 'valid' => 1331196465),
    's7g35b' => 
      array('a' => '32a4djg2sa', 'b' => 'ib78m37fdj', 'valid' => 1331196466));

  echo("Original array \$sess_data:\n");
  var_dump($sess_data);

  $_SESSION['chresp'] = $sess_data;
}
else
{
  echo("Session 'chresp' already exists!\n");
}

echo("fetched from \$_SESSION['chresp']\n");
var_dump($_SESSION['chresp']);

if (count($_SESSION['chresp']) > 2)
  array_shift($_SESSION['chresp']);
$new_element = generateRandomString(6);
$_SESSION['chresp'][$new_element] =
  array('a' => generateRandomString(), 'b' => generateRandomString(), 'valid' => 1331196467);

echo("fetched from \$_SESSION['chresp'] after array_shift'ing and adding new element $new_element\n");

var_dump($_SESSION['chresp']);


?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 19:01:31 2024 UTC