summaryrefslogtreecommitdiff
path: root/ext/mysqli/mysqli_nonapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mysqli/mysqli_nonapi.c')
-rw-r--r--ext/mysqli/mysqli_nonapi.c57
1 files changed, 13 insertions, 44 deletions
diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c
index 918594ad76..87b33f4389 100644
--- a/ext/mysqli/mysqli_nonapi.c
+++ b/ext/mysqli/mysqli_nonapi.c
@@ -109,37 +109,18 @@ PHP_FUNCTION(mysqli_connect)
port, SAFE_STR(username), SAFE_STR(dbname),
SAFE_STR(passwd));
+ mysql->hash_key = hash_key;
+
/* check if we can reuse exisiting connection ... */
if (zend_hash_find(&EG(persistent_list), hash_key, hash_len + 1, (void **)&le) == SUCCESS) {
if (Z_TYPE_P(le) == php_le_pmysqli()) {
plist = (mysqli_plist_entry *) le->ptr;
do {
- if (zend_hash_num_elements(&plist->free_links)) {
- HashPosition pos;
- MYSQL **free_mysql;
- ulong idx;
- dtor_func_t pDestructor = plist->free_links.pDestructor;
-
- zend_hash_internal_pointer_reset_ex(&plist->free_links, &pos);
- if (SUCCESS != zend_hash_get_current_data_ex(&plist->free_links,
- (void **)&free_mysql, &pos)) {
- break;
- }
- if (HASH_KEY_IS_LONG != zend_hash_get_current_key_ex(&plist->free_links, NULL,
- NULL, &idx, FALSE, &pos)) {
- break;
- }
- plist->free_links.pDestructor = NULL; /* Don't call pDestructor now */
- if (SUCCESS != zend_hash_index_del(&plist->free_links, idx)) {
- plist->used_links.pDestructor = pDestructor; /* Restore the destructor */
- break;
- }
- plist->free_links.pDestructor = pDestructor; /* Restore the destructor */
- mysql->mysql = *free_mysql;
+ if (zend_ptr_stack_num_elements(&plist->free_links)) {
+ mysql->mysql = zend_ptr_stack_pop(&plist->free_links);
MyG(num_inactive_persistent)--;
- MyG(num_active_persistent)++;
/* reset variables */
/* todo: option for ping or change_user */
#if G0
@@ -150,16 +131,14 @@ PHP_FUNCTION(mysqli_connect)
#ifdef HAVE_MYSQLND
mysqlnd_restart_psession(mysql->mysql);
#endif
- idx = zend_hash_next_free_element(&plist->used_links);
- if (SUCCESS != zend_hash_next_index_insert(&plist->used_links, &free_mysql,
- sizeof(MYSQL *), NULL)) {
- php_mysqli_dtor_p_elements(free_mysql);
- MyG(num_links)--;
- break;
- }
- mysql->hash_index = idx;
- mysql->hash_key = hash_key;
+ MyG(num_active_persistent)++;
goto end;
+ } else {
+#if defined(HAVE_MYSQLND)
+ mysqlnd_end_psession(mysql->mysql);
+#endif
+ mysqli_close(mysql->mysql, MYSQLI_CLOSE_IMPLICIT);
+ mysql->mysql = NULL;
}
}
} while (0);
@@ -169,8 +148,7 @@ PHP_FUNCTION(mysqli_connect)
le.type = php_le_pmysqli();
le.ptr = plist = calloc(1, sizeof(mysqli_plist_entry));
- zend_hash_init(&plist->free_links, MAX(2, MyG(max_persistent)), NULL, php_mysqli_dtor_p_elements, 1);
- zend_hash_init(&plist->used_links, MAX(2, MyG(max_persistent)), NULL, php_mysqli_dtor_p_elements, 1);
+ zend_ptr_stack_init(&plist->free_links, 1);
zend_hash_update(&EG(persistent_list), hash_key, hash_len + 1, (void *)&le, sizeof(le), NULL);
}
}
@@ -244,18 +222,9 @@ end:
/* store persistent connection */
if (persistent && new_connection) {
- /* save persistent connection */
- ulong hash_index = zend_hash_next_free_element(&plist->used_links);
- if (SUCCESS != zend_hash_next_index_insert(&plist->used_links, &mysql->mysql,
- sizeof(MYSQL *), NULL)) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't store persistent connection");
- } else {
- mysql->hash_index = hash_index;
- }
MyG(num_active_persistent)++;
}
- mysql->hash_key = hash_key;
MyG(num_links)++;
#if !defined(HAVE_MYSQLND)
@@ -274,7 +243,7 @@ end:
err:
efree(mysql);
- if (persistent) {
+ if (hash_key) {
efree(hash_key);
}
RETVAL_FALSE;