zak             Mon Nov 11 20:41:16 2002 EDT

  Modified files:              
    /php4/ext/mysql     php_mysql.c 
  Log:
  Modified php_mysql_do_connect() as suggested by Nick Gaugler - using 
  mysql_ping() as a more efficient alternative to using mysql_stat() to
  check if the server is alive and then calling mysql_(real_)?connect() to 
  reconnect.
  
  Simple tests of opening pconnects indicate that only about 10k of data per 
  ping needs to be returned to the client per connection check, rather than
  about 110k per status check.
  
  
Index: php4/ext/mysql/php_mysql.c
diff -u php4/ext/mysql/php_mysql.c:1.171 php4/ext/mysql/php_mysql.c:1.172
--- php4/ext/mysql/php_mysql.c:1.171    Mon Nov 11 11:54:26 2002
+++ php4/ext/mysql/php_mysql.c  Mon Nov 11 20:41:16 2002
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
  
-/* $Id: php_mysql.c,v 1.171 2002/11/11 16:54:26 iliaa Exp $ */
+/* $Id: php_mysql.c,v 1.172 2002/11/12 01:41:16 zak Exp $ */
 
 /* TODO:
  *
@@ -696,11 +696,19 @@
                        }
                        MySG(num_persistent)++;
                        MySG(num_links)++;
-               } else {  /* we do */
+               } else {  /* The link is in our list of persistent connections */
                        if (Z_TYPE_P(le) != le_plink) {
                                MYSQL_DO_CONNECT_RETURN_FALSE();
                        }
                        /* ensure that the link did not die */
+#if MYSQL_VERSION_ID > 32230 /* Use mysql_ping to ensure link is alive (and to 
+reconnect if needed) */
+                       if (mysql_ping(le->ptr)) {
+                                       php_error(E_WARNING, "%s: Link to server lost, 
+unable to reconnect", get_active_function_name(TSRMLS_C));
+                                       zend_hash_del(&EG(persistent_list), 
+hashed_details, hashed_details_length+1);
+                                       efree(hashed_details);
+                                       MYSQL_DO_CONNECT_RETURN_FALSE();
+                       }
+#else  /* Use mysql_stat() to check if server is alive */
                        handler=signal(SIGPIPE, SIG_IGN);
 #if defined(HAVE_MYSQL_ERRNO) && defined(CR_SERVER_GONE_ERROR)
                        mysql_stat(le->ptr);
@@ -721,6 +729,8 @@
                                }
                        }
                        signal(SIGPIPE, handler);
+#endif /* end Use mysql_ping ... */
+
                        mysql = (php_mysql_conn *) le->ptr;
                }
                ZEND_REGISTER_RESOURCE(return_value, mysql, le_plink);



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to