void (*handler) (int);
handler = signal(SIGPIPE, SIG_IGN);
+#ifdef MYSQL_USE_MYSQLND
+ mysqlnd_end_psession(link->conn);
+#endif
mysql_close(link->conn);
signal(SIGPIPE, handler);
/* ensure that the link did not die */
if (mysql_ping(mysql->conn)) {
if (mysql_errno(mysql->conn) == 2006) {
-#ifndef MYSQL_USE_MYSQLND
- if (mysql_real_connect(mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL)
-#else
+#ifdef MYSQL_USE_MYSQLND
+ mysqlnd_end_psession(mysql->conn);
if (mysqlnd_connect(mysql->conn, host, user, passwd, 0, NULL, 0,
port, socket, client_flags, MySG(mysqlnd_thd_zval_cache) TSRMLS_CC) == NULL)
+#else
+ if (mysql_real_connect(mysql->conn, host, user, passwd, NULL, port, socket, client_flags)==NULL)
#endif
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Link to server lost, unable to reconnect");
MY_MYSQL *mysql = (MY_MYSQL *)my_res->ptr;
if (mysql->mysql) {
if (!mysql->persistent) {
+#ifdef MYSQLI_USE_MYSQLND
+ mysqlnd_end_psession(mysql->mysql);
+#endif
mysqli_close(mysql->mysql, MYSQLI_CLOSE_IMPLICIT);
} else {
zend_rsrc_list_entry *le;
mnd_pefree(conn->last_message, conn->persistent);
conn->last_message = NULL;
}
- conn->zval_cache = cache;
+ /*
+ The thd zval cache is always freed on request shutdown, so this has happened already.
+ Don't touch the old value! Get new reference
+ */
+ conn->zval_cache = mysqlnd_palloc_get_thd_cache_reference(cache);
DBG_VOID_RETURN;
}
/* }}} */
PHPAPI void _mysqlnd_end_psession(MYSQLND *conn TSRMLS_DC)
{
DBG_ENTER("_mysqlnd_end_psession");
- /*
- BEWARE!!!! This will have a problem with a query cache.
- We need to move the data out of the zval cache before we end the psession.
- Or we will use nirvana pointers!!
- */
- if (conn->zval_cache) {
- DBG_INF("Freeing zval cache reference");
- mysqlnd_palloc_free_thd_cache_reference(&conn->zval_cache);
- conn->zval_cache = NULL;
- }
+ /* The thd zval cache is always freed on request shutdown, so this has happened already */
+ conn->zval_cache = NULL;
DBG_VOID_RETURN;
}
/* }}} */
return;
}
+ /*
+ !!! 080624 !!!
+ If the user has used Persistent Connections the reference counter
+ of the cache is not 1 but > 1 . Because the Pconns don't are not signalised
+ during RSHUT, then we need to take care here to decrease the counter.
+ A more proper fix will be to array_walk our pconns in RSHUT and ask them to
+ free their thd reference. This should be implemented sooner or later!
+ */
+
/*
Keep in mind that for pthreads pthread_equal() should be used to be
fully standard compliant. However, the PHP code all-around, incl. the
p = thd_cache->gc_list.ptr_line;
LOCK_PCACHE(cache);
+ /* We need to decrease Main cache's references as pconns don't clean correctly */
+ cache->references -= (thd_cache->references - 1); /* we start with 1 initial reference */
while (p < thd_cache->gc_list.last_added) {
(*p)->point_type = MYSQLND_POINTS_FREE;
*(--cache->free_list.last_added) = *p;
}
UNLOCK_PCACHE(cache);
+ /* We need to decrease thd cache's references as pconns don't clean correctly. See above! */
+ thd_cache->references = 1;
mysqlnd_palloc_free_thd_cache_reference(&thd_cache);
DBG_VOID_RETURN;