Does PHP replicates variables when retrieving from shared memory?

If I run shm_get_var(), it will return a “reference” to save the data in shared memory?

I want to keep an array of about 50MB in shared memory so that it can be used by multiple processes without having to keep multiple copies of this 50MB array. If shared memory is not the answer , Does anyone have another idea?

This is the relevant C code snippet of sysvsem.c in PHP 5.2.9:

< /p>

/* 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) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "variable key %ld doesn't exist", key);
RETURN_FALSE ;
}
shm_var = (sysvshm_chunk*) ((char *)shm_list_ptr->ptr + shm_varpos);
shm_data = &shm_var->mem;

PHP_VAR_UNSERIALIZE_INIT( var_hash);
if (php_var_unserialize(&return_value, (const unsigned char **) &shm_data, shm_data + shm_var->length, &var_hash TSRMLS_CC) != 1) {
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "variable data in shared memory is corrupted");
RETURN_FALSE;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);

Every time shm_get is called , PHP must deserialize the entire value, which is true on a 50MB array Very slow.

How to break it down into personal values?

You can also consider using APC’s variable cache, which will handle all shared memory and locking for you (and will also use a hash table for key lookup)

If I run shm_get_var(), will it return a “reference” to save the data in shared memory?

I want to keep an array of about 50MB in shared memory so that it can be used by multiple processes without having to keep multiple copies of this 50MB array. If shared memory is not the answer , Does anyone have another idea?

This is the relevant C code snippet of sysvsem.c in PHP 5.2.9:

/* 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) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "variable key %ld doesn't exist", key);
RETURN_FALSE;
}
shm_var = (sysvshm_chunk*) ((char *)shm_list_ptr->ptr + shm_varpos);
shm_data = &shm_var->mem;

PHP_VAR_UNSERIALIZE_INIT(var_hash);
if (php_var_unserialize(&shm_var->mem; , (const unsigned char **) &shm_data, shm_data + shm_var->length, &var_hash TSRMLS_CC) != 1) {
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
php_error_docref(NULL TSRMLS_CC, E_WARNING shared data, "variable data in memory is corrupted");
RETURN_FALSE;
}
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);

Every time shm_get is called, PHP must deserialize the entire value, which is It’s really slow on a 50MB array.

How to break it down into personal values?

You can also consider using APC’s variable cache, which will handle all shared memory and locking for you (and will also use a hash table for key lookup)

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2718 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.