[TYPO3-core] RFC #11770: Feature: mysql_ping wrapper
Ries van Twisk
typo3 at rvt.dds.nl
Mon Aug 24 21:18:35 CEST 2009
On Aug 24, 2009, at 2:02 PM, Dan Osipov wrote:
> 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?
Well, I think this should be logged so DBAl users get proper notified...
>
>>
>>
>> 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.
My bad, I was reading with my nose and you where right in this..
"Since MySQL 5.0.13, automatic reconnection feature is disabled. "
>
>>
>>
>> One suggestion is just to execute a 'SELECT 1;' to the database
>> and see
>> if that results in a proper row (some timing issues might appear)
>> doing a 'SELECT 1;' will also work for adodb connected databases.
>>
>
> That might work... I'm not sure. I think there might be other
> reasons a
> query could fail...
>
>>
>> Just come to think of it... doesn't mysql/php not have a keep alive
>> setting?? PostgreSQL has one.....
>
> AFAIK, It doesn't. Things would be much simpler...
>
>>
>>
>>
>> Ries
>>
>>
>> On Aug 24, 2009, at 12:13 PM, Dan Osipov wrote:
>>
>>> Thanks,
>>> Attached is the CGL modified patch
>>>
>>> Dan Osipov
>>> Calkins Media
>>> http://danosipov.com/blog/
>>>
>>> Xavier Perseguers wrote:
>>>> Hi,
>>>> Dan Osipov wrote:
>>>>> Attached is the updated patch that includes the DBAL
>>>>> implementation.
>>>>> Since nothing equivalent to mysql_ping exists in adodb, the
>>>>> function
>>>>> will return true for all other handlers.
>>>> I'm OK with this solution as it is what I suggested in the mail I
>>>> sent you.
>>>> However, I would like CGL to be applied (no tab before {, string
>>>> comparison with === instead of ==, boolean false as FALSE, just as
>>>> typed in comment)
>>>> Regards
>>> Index: t3lib/class.t3lib_db.php
>>> ===================================================================
>>> --- t3lib/class.t3lib_db.php (revision 5810)
>>> +++ t3lib/class.t3lib_db.php (working copy)
>>> @@ -981,6 +981,22 @@
>>> }
>>> return $ret;
>>> }
>>> +
>>> + /**
>>> + * Ping MySQL database to check if the connection is still
>>> alive.
>>> Reconnect if necessary
>>> + * mysql_ping() wrapper function
>>> + *
>>> + * @param bool TRUE if reconnect should be attempted
>>> + * @return mixed Either result of mysql_ping, or new
>>> connection ID if asked to reconnect.
>>> + */
>>> + function sql_ping($reconnect = FALSE) {
>>> + $pingResult = mysql_ping($this->link);
>>> + if (!$pingResult && $reconnect) {
>>> + return $this->sql_pconnect(TYPO3_db_host,
>>> TYPO3_db_username, TYPO3_db_password);
>>> + }
>>> +
>>> + return $pingResult;
>>> + }
>>>
>>>
>>>
>>> Index: typo3/sysext/dbal/class.ux_t3lib_db.php
>>> ===================================================================
>>> --- typo3/sysext/dbal/class.ux_t3lib_db.php (revision 5810)
>>> +++ typo3/sysext/dbal/class.ux_t3lib_db.php (working copy)
>>> @@ -1651,6 +1651,27 @@
>>> function sql_select_db($TYPO3_db) {
>>> return TRUE;
>>> }
>>> +
>>> + /**
>>> + * Ping the database to check if the connection is still alive.
>>> Reconnect if necessary
>>> + * Only _DEFAULT handler is supported. Returns TRUE for other
>>> handlers
>>> + *
>>> + * @param bool TRUE if reconnect should be attempted
>>> + * @return mixed Either result of mysql_ping, or new
>>> connection ID if asked to reconnect.
>>> + */
>>> + function sql_ping($reconnect = FALSE) {
>>> + if ($this->handlerCfg['_DEFAULT']['type'] ===
>>> 'native') {
>>> + $pingResult = mysql_ping($this->link);
>>> + if (!$pingResult && $reconnect) {
>>> + return $this->sql_pconnect(TYPO3_db_host,
>>> TYPO3_db_username, TYPO3_db_password);
>>> + }
>>> +
>>> + return $pingResult;
>>> + }
>>> + else {
>>> + return TRUE;
>>> + }
>>> + }
>>>
>>>
>>>
>>> @@ -1665,7 +1686,6 @@
>>>
>>>
>>>
>>> -
>>> /**************************************
>>> *
>>> * SQL admin functions
>>> _______________________________________________
>>> Before posting to this list, please have a look to the posting rules
>>> on the following websites:
>>>
>>> http://typo3.org/teams/core/core-mailinglist-rules/
>>> http://typo3.org/development/bug-fixing/diff-and-patch/
>>> _______________________________________________
>>> TYPO3-team-core mailing list
>>> TYPO3-team-core at lists.netfielders.de
>>> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-team-core
>>
>>
>> regards, Ries van Twisk
>>
>> -------------------------------------------------------------------------------------------------
>>
>> tags: Freelance TYPO3 Glassfish JasperReports JasperETL Flex Blaze-DS
>> WebORB PostgreSQL DB-Architect
>> email: ries at vantwisk.nl web: http://www.rvantwisk.nl/
>> skype:
>> callto://r.vantwisk
>> Phone: +1-810-476-4196 Cell: +593 9901 7694 SIP:
>> +1-747-690-5133
>>
>>
>>
>>
>>
>>
>>
> _______________________________________________
> Before posting to this list, please have a look to the posting rules
> on the following websites:
>
> http://typo3.org/teams/core/core-mailinglist-rules/
> http://typo3.org/development/bug-fixing/diff-and-patch/
> _______________________________________________
> TYPO3-team-core mailing list
> TYPO3-team-core at lists.netfielders.de
> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-team-core
regards, Ries van Twisk
-------------------------------------------------------------------------------------------------
tags: Freelance TYPO3 Glassfish JasperReports JasperETL Flex Blaze-DS
WebORB PostgreSQL DB-Architect
email: ries at vantwisk.nl web: http://www.rvantwisk.nl/
skype: callto://r.vantwisk
Phone: +1-810-476-4196 Cell: +593 9901 7694 SIP:
+1-747-690-5133
More information about the TYPO3-team-core
mailing list