Seems like a good idea to me. Any volunteers? Zak? ---------- Forwarded message ---------- Date: 11 Nov 2002 23:45:38 -0000 From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: #20374 [NEW]: Performance enhancment for php_mysql_do_connect.
From: [EMAIL PROTECTED] Operating system: Linux PHP version: 4.2.2 PHP Bug Type: MySQL related Bug description: Performance enhancment for php_mysql_do_connect. While investigating server performance I noticed that my queries per second was unusually high, as well as my SHOW STATUS commands in MySQL. After investigating through the source, I found the function php_mysql_do_connect, which of course does connections. Within there, line 602 of php_mysql.c for 4.2.2, I found a mysql_stat() where the MySQL connection was tested, and upon failure would reconnect. My suggestion for PHP, and what I am placing into my own source, is instead of a mysql_stat, a mysql_ping is ran, if the API library is above 3.22.3 (http://www.mysql.com/documentation/mysql/bychapter/index.html#News-3.22.3) Per the MySQL documentation: http://www.mysql.com/documentation/mysql/bychapter/manual_Clients.html#mysql_ping int mysql_ping(MYSQL *mysql) 8.4.3.164 Description Checks whether the connection to the server is working. If it has gone down, an automatic reconnection is attempted. This function can be used by clients that remain idle for a long while, to check whether the server has closed the connection and reconnect if necessary. 8.4.3.165 Return Values Zero if the server is alive. Non-zero if an error occurred. Since the libmysqlclient API will already reconnect, there is no need for PHP to do this internally. If the API version is equal to or above 3.22.3, run a mysql_ping and upon failure, remove the connection from the zend_hash and return failure. If it is below 3.22.3 (which is 3 years old), run the old source. I know this is not a huge change, but it does make alittle difference in performance. Below is a test.c example of how this functions: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <mysql.h> int main (void) { MYSQL mysql_connect; MYSQL_RES *mysql_result; MYSQL_ROW mysql_row; my_ulonglong id; int c; mysql_init(&mysql_connect); mysql_real_connect(&mysql_connect,"localhost","root","inT99hB$", "mysql", 0, NULL, 0); for (c = 0; c < 3; c++) { sleep(2); mysql_ping(&mysql_connect); printf("Error: %s\n", mysql_error(&mysql_connect)); if (mysql_real_query(&mysql_connect,"SELECT CONNECTION_ID()",sizeof("SELECT CONNECTION_ID()"))) { printf("Error querying: %s\n", mysql_error(&mysql_connect)); } else { mysql_result = mysql_store_result(&mysql_connect); mysql_row = mysql_fetch_row(mysql_result); id = strtoul(mysql_row[0], NULL, 0); mysql_free_result(mysql_result); printf("Id is %lu\n", id); mysql_kill(&mysql_connect, id); } } } Example of php_mysql.c #if MYSQL_VERSION_ID > 32230 /* let mysql_ping check connection and auto reconnect */ if(mysql_ping(le->ptr)) { php_error(E_WARNING, "MySQL: Link to server lost, unable to reconnect"); zend_hash_del(&EG(persistent_list), hashed_details, hashed_details_length+1); efree(hashed_details); MYSQL_DO_CONNECT_RETURN_FALSE(); } #else ... normal code... #endif Bests, nickg -- Edit bug report at http://bugs.php.net/?id=20374&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=20374&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=20374&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=20374&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=20374&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=20374&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=20374&r=support Expected behavior: http://bugs.php.net/fix.php?id=20374&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=20374&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=20374&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=20374&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20374&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=20374&r=dst IIS Stability: http://bugs.php.net/fix.php?id=20374&r=isapi -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php