shared memory: shm_has_var
| From: | matt dot wong at tumbleweed dot com | Date: | Fri, 08 Dec 2000 23:58:46 +0000 |
| Subject: | shared memory: shm_has_var | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-40618@lists.php.net to get a copy of this message | ||
Hello,
I found it necessary to add a function to the sysvshm module: shm_has_var. It returns true if a variable exists in shared memory, and false otherwise. The reason this was necessary is that if the shared memory had not already been initialized, shm_get_var raises a warning. I'd prefer to keep seeing my warnings, but not to see this one. If there was a way to do this with the existing PHP functions or configuration switches, please let me know. On a somewhat related issue, why is shared memory is maintained even when apache is shutdown and then restarted?
So here's the code, basically an exact copy of shm_get_var() that returns a boolean instead of the var value.
-Matt
40d39 < PHP_FE(shm_has_var, NULL) 295,333d293 < /* }}} */ < < /* {{{ proto mixed shm_has_var(int id, int variable_key) < Returns true iff variable exists in shared memory */ < PHP_FUNCTION(shm_has_var) < { < pval **arg_id, **arg_key; < long key, id; < sysvshm_shm *shm_list_ptr; < int type; < char *shm_data; < long shm_varpos; < sysvshm_chunk *shm_var; < < if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg_id, &arg_key) == FAILURE) { < WRONG_PARAM_COUNT; < } < < convert_to_long_ex(arg_id); < id = (*arg_id)->value.lval; < convert_to_long_ex(arg_key); < key = (*arg_key)->value.lval; < < shm_list_ptr = (sysvshm_shm *) zend_list_find(id, &type); < if (type!=php_sysvshm.le_shm) { < php_error(E_WARNING, "%d is not a SysV shared memory index", id); < RETURN_FALSE; < } < < /* setup string-variable and serialize */ < /* get serialized variable from shared memory */ < shm_varpos=php_check_shm_data((shm_list_ptr->ptr),key); < < if(shm_varpos<0) { < RETURN_FALSE; //doesn't exist < } else { < RETURN_TRUE; < } < } 70d69 < PHP_FUNCTION(shm_has_var);
40d39 < PHP_FE(shm_has_var, NULL) 295,333d293 < /* }}} */ < < /* {{{ proto mixed shm_has_var(int id, int variable_key) < Returns true iff variable exists in shared memory */ < PHP_FUNCTION(shm_has_var) < { < pval **arg_id, **arg_key; < long key, id; < sysvshm_shm *shm_list_ptr; < int type; < char *shm_data; < long shm_varpos; < sysvshm_chunk *shm_var; < < if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg_id, &arg_key) == FAILURE) { < WRONG_PARAM_COUNT; < } < < convert_to_long_ex(arg_id); < id = (*arg_id)->value.lval; < convert_to_long_ex(arg_key); < key = (*arg_key)->value.lval; < < shm_list_ptr = (sysvshm_shm *) zend_list_find(id, &type); < if (type!=php_sysvshm.le_shm) { < php_error(E_WARNING, "%d is not a SysV shared memory index", id); < RETURN_FALSE; < } < < /* setup string-variable and serialize */ < /* get serialized variable from shared memory */ < shm_varpos=php_check_shm_data((shm_list_ptr->ptr),key); < < if(shm_varpos<0) { < RETURN_FALSE; //doesn't exist < } else { < RETURN_TRUE; < } < } 70d69 < PHP_FUNCTION(shm_has_var);