简体   繁体   中英

json encode breaking for large strings

I am trying to json encode an well-formed XML string into a SimpleXMLElement object. But what happens is that, it breaks or exit .

I tried with small xml files and works fine and the issue is with large xml files

Here is the code:

<?php
$directory = "lookup.xml";
$xmlContent = file_get_contents($directory); // get contents of lookup
print_r(simplexml_load_string($xmlContent));
$arrayXml = json_decode(json_encode(simplexml_load_string($xmlContent)),TRUE);
print_r($arrayXml);

lookup.xml files :

1. lookup.xml - 2 MB (works fine)
2. lookup.xml - 13 MB (Not working)

Is it because of a large file or some string breaking??

What are exactly error messages, loading 13Mb into XML than into JSON will take lot of memory, what is memory limit on your server. With your code I have tried XML sitemap of 7.5 MB and memory_get_peak_usage() at the end of script showed 119MB usage for 13 it would be almost twice depending on XML itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM