Our distributed database have php client which is developed on php extension. We store our database object in persistant_list.
Problem: From the log we find, for the same process, sometimes it can't find the database object from persistent_list, have to init the db object in persistant_list, but later(probably 1s)it can't find the same key-value again. It seems the value in persistent list is destroyed. Based on my poor knowledge about php, the values in persistent_list only destroyed by zend_hash_del or web server down. Source code:
if (zend_hash_find(&EG(persistent_list), hash_key, hash_key_len+1, (void **) &le) == FAILURE) {
tc = tair_init();
last_rst = tair_startup(tc,uri);
if(last_rst != TAIR_RETURN_SUCCESS){
return -1;
}
zend_rsrc_list_entry new_le;
new_le.type = le_tair;
new_le.ptr = tc;
/* register new persistent connection */
if (zend_hash_update(&EG(persistent_list), hash_key, hash_key_len+1, (void *) &new_le, sizeof(zend_rsrc_list_entry), NULL) == FAILURE) {
tair_deinit(tc);
tc = NULL;
} else {
rsrc_id = zend_list_insert(tc,le_tair);
}
}else if (le->type != le_tair || le->ptr == NULL) {
zend_hash_del(&EG(persistent_list), hash_key, hash_key_len+1);
tc = tair_init();
last_rst = tair_startup(tc,uri);
if(last_rst != TAIR_RETURN_SUCCESS){
return -1;
}
zend_rsrc_list_entry new_le;
new_le.type = le_tair;
new_le.ptr = tc;
if (zend_hash_update(&EG(persistent_list), hash_key, hash_key_len+1, (void *) &new_le, sizeof(zend_rsrc_list_entry), NULL) == FAILURE) {
tair_deinit(tc);
tc = NULL;
} else {
rsrc_id = zend_list_insert(tc,le_tair);
}
}else {
tc = (tair_handler)le->ptr;
rsrc_id = zend_list_insert(tc,le_tair);
}
PHP_MINIT_FUNCTION(tair)
{
REGISTER_INI_ENTRIES();
tair_set_loglevel(tair_globals.log_level);
le_tair = zend_register_list_destructors_ex(NULL,tair_dtor,"Tair session", module_number);
return SUCCESS;
}
Can anyone tell me what's wrong with my php zend engine? Btw the client side use Nginx+fpm.