downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

shm_remove_var> <shm_has_var
Last updated: Fri, 14 Aug 2009

view this page in

shm_put_var

(PHP 4, PHP 5)

shm_put_varInsère ou modifie une variable de la mémoire partagée

Description

bool shm_put_var ( resource $shm_identifier , int $variable_key , mixed $variable )

shm_put_var() insère ou modifie la variable variable avec la clé variable_key dans le segment de mémoire shm_identifier .

Des alertes (niveau E_WARNING) seront émises si shm_identifier n'est pas un segment de mémoire système V valide, ou s'il n'y a pas assez de mémoire pour votre requête.

Liste de paramètres

shm_identifier

Une ressource, représentant la mémoire partagée, telle que retournée par la fonction shm_attach()

variable_key

La clé de la variable.

variable

La variable. Tous les types de variables sont supportés.

Valeurs de retour

Cette fonction retourne TRUE en cas de succès, FALSE en cas d'échec.

Voir aussi

  • shm_get_var() - Lit une variable dans la mémoire partagée
  • shm_has_var() - Vérifie si une variable existe en mémoire partagée



shm_remove_var> <shm_has_var
Last updated: Fri, 14 Aug 2009
 
add a note add a note User Contributed Notes
shm_put_var
ygbr at me dot com
12-Oct-2009 09:25
Will it ever support resource identifiers like pfsockopen() pointers?

The main problem is that when we run PHP as a Apache Module we never know in which process the next request will bind to, making impossible to have true persistent socket connections unless we can store the pointer to it or directly open the socket inode with fopen() like functions and retrieve the same resource pointer again.

I thought I could use shm, but it seems that shm doesn't allow o store resource pointers... sad... :(
Hendrik Klindworth
02-Feb-2009 04:28
shm_put_var has no protection against race conditions. If two scripts insert the same key at the same time php might segfault.
jasonrlester at yahoo dot com
25-Apr-2008 07:51
sadly troy is right

the following script will return:

resource(5) of type (stream)
int(0)

<?php

define
("FOPEN_RESOURCE", 1);
define("FOPEN_FILEPATH", "/path/to/file");

$fopen_resource = fopen(FOPEN_FILEPATH, "w");

var_dump($fopen_resource);

$shm_id = shm_attach(1);
if (
$shm_id === false)
{
    echo
"Fail to attach shared memory.\n";
}

if (!
shm_put_var($shm_id, FOPEN_RESOURCE, $fopen_resource))
{
    echo
"Failed to put var 1 in shared memory $shm_id.\n";
}

$sm_fopen_resource = shm_get_var($shm_id, FOPEN_RESOURCE);
if (
$sm_fopen_resource === false)
{
    echo
"Failed to retreive fopen_resource from Shared memory\r\n";
}

var_dump($sm_fopen_resource);

if(
$shm_id) shm_remove($shm_id);
if(
$fopen_resource) fclose($fopen_resource);

?>
troy
06-Mar-2008 03:02
This isn't entirely accurate. Not all variable types are supported, you can't put a resource variable into shared memory.

When you try to take it out, it will be a zero.
tomlove at gmail dot com
30-Sep-2004 11:53
Use as few variable_keys as you can. With large arrays of data, rather make the array multi-dimensional and store under one variable_key than use variable_key as your index. The benefit is especially noticeable when repeated fetching from the end of the array is necessary and updates are less frequent.

shm_remove_var> <shm_has_var
Last updated: Fri, 14 Aug 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites