Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:5851 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90873 invoked by uid 1010); 1 Dec 2003 07:25:46 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 90849 invoked from network); 1 Dec 2003 07:25:46 -0000 Received: from unknown (HELO miranda.org) (209.58.150.153) by pb1.pair.com with SMTP; 1 Dec 2003 07:25:46 -0000 Received: (qmail 10958 invoked by uid 546); 1 Dec 2003 07:25:42 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 1 Dec 2003 07:25:42 -0000 Date: Mon, 1 Dec 2003 02:25:42 -0500 (EST) X-X-Sender: adam@miranda.org To: internals@lists.php.net Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: PHP 5 libxml2 Error Handler Broken From: adam@trachtenberg.com (Adam Maccabee Trachtenberg) We've defined a custom libxml2 error handler, php_libxml_error_handler(), that makes error messages go through php_error() instead of printing to stderr. Unfortunately, libxml2 doesn't make one call to the error function for each error. Sometimes it seems to do it once per character. Unfortunately, this makes the error log look crazy. For instance: $s = domDocument::load('http://www.php.net/news.rss'); $xpath = new domXpath($s); $nodes = $xpath->query('//rss:title'); Gives: PHP Warning: XPath error Undefined namespace prefix in /home/adam/xml-test.php on line 7 PHP Warning: / in /home/adam/xml-test.php on line 7 PHP Warning: / in /home/adam/xml-test.php on line 7 PHP Warning: r in /home/adam/xml-test.php on line 7 PHP Warning: s in /home/adam/xml-test.php on line 7 PHP Warning: s in /home/adam/xml-test.php on line 7 PHP Warning: : in /home/adam/xml-test.php on line 7 PHP Warning: t in /home/adam/xml-test.php on line 7 PHP Warning: i in /home/adam/xml-test.php on line 7 PHP Warning: t in /home/adam/xml-test.php on line 7 PHP Warning: l in /home/adam/xml-test.php on line 7 PHP Warning: e in /home/adam/xml-test.php on line 7 ... (and about 12 more lines after this.) It should look something like: PHP Warning: XPath error Undefined namespace prefix in /home/adam/xml-test.php on line 7 PHP Warning: //rss:title in /home/adam/xml-test.php on line 7 PHP Warning: ^ in /home/adam/xml-test.php on line 7 Reviewing libxml2 error messages, I propose we create a libxml2 error buffer that only gets flushed when libxml2 sends us a string that ends in "\n". Otherwise, we just append the new error to the buffer. I have a patch that does this. Unfortunately, I'm unsure of the best way to maintain the buffer between calls. I'm pretty sure I'm not allowed to just declare it "static" within php_libxml_error_handler(). My current patch makes it a global variable, which seems just as bad. I'm not worried too much about concurrency issues because if libxml2 doesn't make atomic error calls, we can't fix it on our end. However, it would be nice if each extension / instance that uses this error function maintain its own buffer, or is that not really an issue? The patch is up at: http://www.trachtenberg.com/patches/php_libxml_error_handler.txt -adam -- adam@trachtenberg.com