Jump to content
Sign in to follow this  
abartsch

XML translation caused segmentation fault

Recommended Posts

Hello, my following PHP code i.e. the last line causes a segmentation fault from time to time:

	$xml = new DOMDocument;	$xml->formatOutput = true;	$xml->load("xml/$hostname.log.xml");	$elements = $xml->getElementsByTagName("*");	foreach($elements as $element)	{	 $type = $element->getAttribute('type');	 $title = $element->getAttribute('title');	 if($type == 'comment' or $title == 'Installed Packages')	 {	  foreach($element->childNodes as $item)	  {	   if($item->nodeType == 4) // XML_CDATA_SECTION_NODE	   {		$cdataWrapper = $xml->createElement("wrapper", $item->nodeValue);		$element->parentNode->appendChild($cdataWrapper);	   }	  }	 }	}	$xsl = new DOMDocument;	$xsl->load("xml/wrapper.xsl");	$proc = new XSLTProcessor;	$proc->importStyleSheet($xsl);	print(trim($proc->transformToXML($xml))); // --> Might cause a segmentation fault

Instead of print I also tried echo. Then, I thought it might be a timing issue and thus, I added a usleep but this could not solve my problem. I also restarted the apache server and cleaned up the memory and swap without success. I'm able to call the page up to five times w/o having any problem but afterwards the segmentation fault is written to the apache error log and the HTML code following after the print is not displayed anymore. I'm using Apache/2.2.22 (Unix) PHP/5.4.0 with libxml 2.7.8 and libxslt 1.1.26 as well on a Linux platform. Any help is highly appreciated! PS: The wrapper is used to additional encapsulate CDATA blocks to be able to address them separately within a wrapper tag. For more details about the wrapper see my other post "How to address CDATA blocks".

Share this post


Link to post
Share on other sites

Could you possibly upgrade PHP? Segfaults are typically a C related problem that can't easily be diagnosed from higher levels like XML/XSLT/PHP. There is a new libxml version (2.8.0), and chances are the latest PHP includes that latest libxml.If even that doesn't help, you'll have to reduce the example a little (hardcode the XML file, make both the XML and XSLT as small as possible, as long as they still keep segfault-ing, remove the trim and formatOutput if they don't have anything to do with this), and submit a bug report to PHP and/or to libxml.

Share this post


Link to post
Share on other sites

Thanks, boen_robot! We installed the new PHP version 5.4.5 and are going to install the new libxml2 version 2.8.0 soon. Anyway, I found a workaround i.e. now I save the modified XML file first, open the saved XML file and do the transformation finally. Here is the modified code snippet:

    $xml = new DOMDocument;    $xml->formatOutput = true;    $xml->load("xml/$hostname.log.xml");    $elements = $xml->getElementsByTagName("*");    foreach($elements as $element)    {	 $type = $element->getAttribute('type');	 $title = $element->getAttribute('title');	 if($type == 'comment' or $title == 'Installed Packages')	 {	  foreach($element->childNodes as $item)	  {	   if($item->nodeType == 4) // XML_CDATA_SECTION_NODE	   {	    $cdataWrapper = $xml->createElement("wrapper", $item->nodeValue);	    $element->parentNode->appendChild($cdataWrapper);	   }	  }	 }    }    // WA for segmentation fault starts here ...    $xml->save("xml/$hostname.wrapper.xml");    $xml = new DOMDocument;    $xml->formatOutput = true;    $xml->load("xml/$hostname.wrapper.xml");    // WA for segmentation fault ends here ...    $xsl = new DOMDocument;    $xsl->load("xml/wrapper.xsl");    $proc = new XSLTProcessor;    $proc->importStyleSheet($xsl);    print(trim($proc->transformToXML($xml))); // --> Might cause a segmentation fault

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...