[TYPO3-core] RFC: minor optimisation of getRecordRaw()

Martin Kutschker Martin.Kutschker at n0spam-blackbox.net
Mon Dec 4 18:26:02 CET 2006


Martin Kutschker schrieb:
> Dmitry Dulepov schrieb:
> 
>> Hi!
>>
>> Martin Kutschker wrote:
>>
>>> Maybe you could use both. Into devLog log everything, into sysLog log 
>>> only the immediate caller of t3lib_db-code (instead of the complete 
>>> backtrace).
>>
>>
>> Hm, good idea. Added & commited to trunk.
> 
> That was not quite what I meant.

The function did not work out nice in the real world. The serialized 
backtrace may contain objects which in case of the FE is huge. It's so 
large that it doesn't fit in a Mysql TEXT field. I have changed the 
function so that it doesn't store the objects, but only the class names.

I have also changed the message string as suggested by me.

I have not removed the PHP version check. If we decide for 4.3 we should 
look for version and functions with grep.

The function looks now like this:

function debug_check_recordset($res) {
   if (!$res) {
    $trace = FALSE;
    $msg = 'Invalid database result resource detected';
    if (version_compare(phpversion(), '4.3.0', '>=')) {
       $trace = debug_backtrace();
     array_shift($trace);
     $cnt = count($trace);
     for ($i=0; $i<$cnt; $i++) {
       // complete objects are too large for the log
      if (isset($trace['object'])) unset($trace['object']);
     }
     $msg .= ': function t3lib_DB->' . $trace[0]['function'] .
      ' called from file ' . substr($trace[0]['file'],strlen(PATH_site)+2) .
      ' in line ' . $trace[0]['line'];
    }
    t3lib_div::sysLog($msg.'. Use a devLog extension to get more details.',
     'Core/t3lib_db', 3);
    t3lib_div::devLog($msg.'.', 'Core/t3lib_db', 3, $trace);

    return FALSE;
   }
   return TRUE;
}

I have tested this and my logs look nice :-)

Shall we use @ with all "protected" mysql_* functions? If we do this you 
must turn on logging, as no PHP warnings will popup on your dev site. For 
the BE we could add something like Mozilla/Firefox's JS Console in IE 
style. Ie. when an error occurs an icon will show up. When you click on it 
you'll see log entries. But this could perhaps be done with a devlog extension.

Masi


More information about the TYPO3-team-core mailing list