php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26177 Can't store multiple variables in SHM
Submitted: 2003-11-08 10:06 UTC Modified: 2003-11-09 23:13 UTC
From: l_faillie at yahoo dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 4.3.3 OS: Solaris 8
Private report: No CVE-ID: None
 [2003-11-08 10:06 UTC] l_faillie at yahoo dot com
Description:
------------
Hi all,

It seems only one variable can be stored in a SHM zone.

Reproduce code:
---------------
Source 1 : storing variables

$shm = shm_attach( 2710, 512);	

shm_put_var( $shm, 'val', 'blabla');
shm_put_var( $shm, 'jour', date('D'));

Source 2 : reading variables

$shm = shm_attach( 2710, 512);
echo 'val :', shm_get_var($shm, 'val'), "\n";
echo 'jour :', shm_get_var($shm, 'jour'), "\n";

Expected result:
----------------
val :blabla
jour :Sat

Actual result:
--------------
val :Sat
jour :Sat


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-08 12:42 UTC] cunha17 at uol dot com dot br
In fact, you should use an array if you want to store multiple information.

Source 1 : storing variables

$shm = shm_attach( 2710, 512);	
$data = array('val'=>'blabla', 
              'jour'=> date('D'));
shm_put_var( $shm, 'data', serialize($data));


Source 2 : reading variables

$shm = shm_attach( 2710, 512);
$data = unserialize(shm_get_var($shm, 'data'));
echo 'val :', $data['val'], "\n";
echo 'jour :', $data['jour'], "\n";
 [2003-11-08 12:49 UTC] l_faillie at yahoo dot com
Yes it was my workaround but ... if it's the correct beaviour of this function, what is the usefullness of the second argument ?
 [2003-11-08 15:50 UTC] cunha17 at uol dot com dot br
oops! It seems that the second argument should be an integer:

int shm_put_var ( int shm_identifier, int variable_key, mixed variable)
 [2003-11-09 23:13 UTC] iliaa@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

The non-numeric keys get converted to 0, which causes the variable to be overwritten.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 19:01:28 2024 UTC