[TYPO3-core] RFC #11770: Feature: mysql_ping wrapper

Martin Kutschker masi-no at spam-typo3.org
Mon Aug 24 21:37:06 CEST 2009


Dan Osipov schrieb:
> Ries van Twisk wrote:
>> Looking at class.ux_t3lib_db.php,
>>
>> in the case of DBAL you can connect to multiple database so you might
>> want to test all connected databases and
>> do something appropriate OR at least log a message that this function
>> does not support DBAL and
>> only will ONYL ping a native mysql DB.
>>
>> However just returning TRUE might lead to incorrect decisions for a
>> programmer when using this function and DBAL with non-mysql databases,
>> or one native DB and a non-native DB...
> 
> The PHPDoc comment to the function in DBAL basically states that. I
> don't think there is a better alternative - do you?
> 
>>
>>
>> One potential problem I see with this function is that mysql_ping can
>> reconnect!!!! (really stupid decission of these people.....)
>>
>> "Checks whether or not the connection to the server is working. If it
>> has gone down, an automatic reconnection is attempted. This function
>> can be used by scripts that remain idle for a long while, to check
>> whether or not the server has closed the connection and reconnect if
>> necessary."
>>
>> that means that the function sql_ping does a double connect!!!! THis
>> doesn't sounds right to me.....
> 
> I think the manual is wrong. I've used the function on several versions
> of MySQL, and it returns FALSE instead of reconnecting. That's why I
> implemented a reconnection procedure.

I guess the PHP function is just a wrapper for the C API. Whether
mysql_ping() reconnects or not depends on the MYSQL_OPT_RECONNECT option.

20.9.3.50. mysql_ping()

int mysql_ping(MYSQL *mysql)

Description

Checks whether the connection to the server is working. If the
connection has gone down and auto-reconnect is enabled an attempt to
reconnect is made. If the connection is down and auto-reconnect is
disabled, mysql_ping() returns an error.

Auto-reconnect is enabled by default before MySQL 5.0.3 and enabled from
5.0.3 on. To enable auto-connect, call mysql_options() with the
MYSQL_OPT_RECONNECT option. For details, see Section 20.9.3.49,
“mysql_options()”.



More information about the TYPO3-team-core mailing list