]> granicus.if.org Git - php/commitdiff
MFH: fix #38996 (PDO_MYSQL doesn't check connections for liveness)
authorAntony Dovgal <tony2001@php.net>
Mon, 2 Oct 2006 22:09:49 +0000 (22:09 +0000)
committerAntony Dovgal <tony2001@php.net>
Mon, 2 Oct 2006 22:09:49 +0000 (22:09 +0000)
NEWS
ext/pdo_mysql/mysql_driver.c

diff --git a/NEWS b/NEWS
index 9ba7c7fe7b75e4fe64dd29269da3d780bc09531c..63314e3d717ed49ab6d87401346106676bf364b9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ PHP                                                                        NEWS
 - Fixed bug #39003 (__autoload() is called for type hinting). (Dmitry, Tony)
 - Fixed bug #39001 (ReflectionProperty returns incorrect declaring class for 
   protected properties). (Tony)
+- Fixed bug #38996 (PDO_MYSQL doesn't check connections for liveness). (Tony)
 - Fixed bug #38993 (Fixed safe_mode/open_basedir checks for
   session.save_path, allowing them to account for extra parameters). (Ilia)
 - Fixed bug #38981 (using FTP URLs in get_headers() causes crash). (Tony)
index 51e502ccaa80f7687dbd6c01364692ccaf8050fa..9b77ea55374280b38cfd44ae9f8931992286d445 100755 (executable)
@@ -379,6 +379,34 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value
        return 1;
 }
 
+static int pdo_mysql_check_liveness(pdo_dbh_t *dbh TSRMLS_DC) /* {{{ */
+{
+       pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
+#if MYSQL_VERSION_ID <= 32230
+       void (*handler) (int);
+       unsigned int my_errno;
+#endif
+
+#if MYSQL_VERSION_ID > 32230
+       if (mysql_ping(H->server)) {
+               return FAILURE;
+       }
+#else /* no mysql_ping() */
+       handler=signal(SIGPIPE, SIG_IGN);
+       mysql_stat(H->server);
+       switch (mysql_errno(H->server)) {
+               case CR_SERVER_GONE_ERROR:
+               /* case CR_SERVER_LOST: I'm not sure this means the same as "gone" for us */
+                       signal(SIGPIPE, handler);
+                       return FAILURE;
+               default:
+                       break;
+       }
+       signal(SIGPIPE, handler);
+#endif /* end mysql_ping() */
+       return SUCCESS;
+} 
+/* }}} */
 
 static struct pdo_dbh_methods mysql_methods = {
        mysql_handle_closer,
@@ -392,7 +420,7 @@ static struct pdo_dbh_methods mysql_methods = {
        pdo_mysql_last_insert_id,
        pdo_mysql_fetch_error_func,
        pdo_mysql_get_attribute,
-       NULL /* check_liveness: TODO: ping */
+       pdo_mysql_check_liveness
 };
 
 #ifndef PDO_MYSQL_UNIX_ADDR