2

現在、大きな XML ファイルのインポートで問題が発生しており、その理由がわかりません。サイズが約 443MB の XML 出力をパートナーから取得します。私が得るエラーは次のとおりです。

PHP Warning:  SimpleXMLElement::__construct(): Entity: line 1: parser error : internal error in /home/imports/catalog.php on line 54

Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : internal error in /home/imports/catalog.php on line 54
PHP Warning:  SimpleXMLElement::__construct(): ch to marriage, parenting, entrepreneurship, etc will be significantly upgraded. in /home/imports/catalog.php on line 54

Warning: SimpleXMLElement::__construct(): ch to marriage, parenting, entrepreneurship, etc will be significantly upgraded. in /home/imports/catalog.php on line 54
PHP Warning:  SimpleXMLElement::__construct():
 ^ in /home/imports/catalog.php on line 54

Warning: SimpleXMLElement::__construct():
 ^ in /home/imports/catalog.php on line 54
PHP Fatal error:  Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/imports/catalog.php:54
Stack trace:
#0 /home/imports/catalog.php(54): SimpleXMLElement->__construct('<?xml version="...')
#1 {main}
  thrown in /home/imports/catalog.php on line 54

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/imports/catalog.php:54
Stack trace:
#0 /home/imports/catalog.php(54): SimpleXMLElement->__construct('<?xml version="...')
#1 {main}
  thrown in /home/imports/catalog.php on line 54

コードの 54 行目は次のとおりです。

$xml = new SimpleXMLElement(file_get_contents($_CFG_XML_URL));

私が知る限り、エラーは を含む要素にあるようですch to marriage, parenting, entrepreneurship, etc will be significantly upgraded.。残念ながら、これはファイルへの長い道のりであり、そのサイズのために内容を読み取るのが困難です. 私の大きなファイル リーダーは一度に 1 行ずつ読み取りますが、この XML はすべて 1 行にあるため、32 GB の RAM と 64 ビットのエディターを備えたワークステーションであっても、適切に処理するには多すぎます。

ファイルを数回再ダウンロードしようとしましたが、問題は常に同じです。スクリプトに使用できるメモリを 2 倍にしましたが、同じ場所で失敗します。

そこで、パートナーに連絡して、この特定のアイテムの XML を要求したところ、次のものが提供されました。

<EBook EAN="9792219192201">
    <Title>Success-a-Phobia</Title>
    <SubTitle>Discovering And Conquering Mankinds Most Persuasive, but Unknown, Phobia</SubTitle>
    <Publisher>The Benjamin Consulting Group, LLC</Publisher>
    <PublicationDate>29/09/2012</PublicationDate>
    <Contributors>
        <Contributor Code="A01" Text="By (author)">Benjamin, Marcus D.</Contributor>
    </Contributors>
    <Formats>
        <Format Type="6"/>
    </Formats>
    <ShortDescription>People today still desire to be successful in matters of family, finance or business even though we are in the midst of major social, political and economic challenges. Have you every been at that moment where you wanted to do something significant, yet you were paralyzed from making the necessary choices to realize your dream? Have you experienced failure and are now sitting in the stands, paralyzed from getting back in the &amp;quote;game of life?&amp;quote;  Are you at the verge of a major decision that could affect your life for many years? If you are in this category, this is your book of the year!    With humor, real-life antidotes, real-life examples and solid narration, Marcus Benjamin will guide you toward discovering the most pervasive, yet unknown, phobia in the history of mankind.  Once this phobia is discovered, the second half of the book shows you how to rid yourself of this phobia for good. Not only will this book impact your life, but your approach to marriage, parenting, entrepreneurship, etc will be significantly upgraded.</ShortDescription>
</EBook>

その XML について私に警鐘を鳴らすものは何もありませんが、明らかに PHP の途中で問題が発生しています。要素のコンテンツには 978 文字あるように見えますが、それは私にとって特別な警鐘を鳴らすものではありません。

PHP スクリプトは、Amazon EC2 インスタンスのコマンドラインから実行されています。OS は Amazon Linux (RHEL) です。

だから、基本的に、私は立ち往生しています。この問題を引き起こしている可能性のあるアイデアはありますか?

4

2 に答える 2

0

978 はベルを鳴らさないかもしれませんが、1000 はベルを鳴らします! 行頭の 4 つのスペースと、'<ShortDescription>' の 18 文字で、必要な 22 文字が提供されます。1000 のようなラウンド数では、ある種のバッファー長制限が発生する可能性が高くなります。

于 2012-12-21T22:36:43.240 に答える
0

を使用して xml を検証してみてくださいxmllint。Linux のコマンド ライン ツールとして利用できます。

ファイルが有効な場合。ini memory_limitvar. DOM 処理 (単純な xml のように) では、ファイル全体をメモリに保持する必要があることに注意してください。あなたの場合、memory_limitは少なくとも500MBに設定する必要があります。

メモリ制限を増やすことができない場合は、xml を解析するためのメモリ消費量を減らす方法を検討する必要があります。この状況では SAX が適しているかもしれませんが、プログラミングにはさらに注意が必要です。

PHP では、SAX は xml 拡張機能を介して使用でき、デフォルトで有効になっています。ここでドキュメントを見つけることができます

于 2012-12-20T20:12:31.860 に答える