Skip to content
Advertisement

Cannot echo or json_decode long JSON string

I’m working with a large JSON data file (25 mb) in PHP.

Right now, I’m able to get the file and check it’s string length, which I get 24479798 for, although I can’t echo out the string.

After the echo strlen(), the rest of the script breaks down and I get no further outputs, including the echo "Made it to the bottom";

Why can’t I get json_decode to work? Is this a script memory problem, a character encoding problem in the JSON data? I’m pretty stuck.

JavaScript

Advertisement

Answer

Considering your trying to import a large file, the script runs longer than a browser/server will like, and will timeout before it finishes. Scripts like this need to be run on the command line or via cron to eliminate the timeout. You can also increase the memory by adding ini_set('memory_limit', '512M'); (or higher, as needed) to the beginning of the script to make sure it has enough memory to load and process the json file.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement