Note that there are some explanatory texts on larger screens.

plurals
  1. POParse large text file with Perl crashes when run from PHP
    primarykey
    data
    text
    <p>I'm using Perl script to parse and create JSON output for use in PHP.</p> <p>Basically I'm parsing large text files(5-20MB) using Perl, with data as following:</p> <pre><code>XXXXXXYYYYYYYYYYYYYZZZZZZZZZYYYYYYYYYPPPPPPPPPPP XXXXXXYYYYYYYYYYYYYZZZZZZZZZYYYYYYYYYPPPPPPPPPPP XXXXXXYYYYYYYYYYYYYZZZZZZZZZYYYYYYYYYPPPPPPPPPPP XXXXXXYYYYYYYYYYYYYZZZZZZZZZYYYYYYYYYPPPPPPPPPPP </code></pre> <p>The script prints JSON output of each line of data from file:</p> <pre><code>{ "1" : "XXXXXXYYYYYYYYYYYYYZZZZZZZZZYYYYYYYYYPPPPPPPPPPP", "2": ... } </code></pre> <p>When ran from terminal, it goes over 100,000 lines of such file in 1.5 seconds, successfully creating JSON.</p> <p>But when I run the script from within PHP using </p> <pre><code>exec("/usr/bin/perl script.pl input_file.txt",$output); print_r(json_decode($output[0],true); </code></pre> <p>it crashed. Though, if I give it file with 2000-3000 lines, it works well. Not using json_decode and only doing var_dump of $output variable works as well.</p> <p>I assume it has to do with json_decode.</p> <p>Is there other way to do this? Suggestions? Solutions?</p> <p>p.s. I've increased the PHP memory_limit to 128MB.</p> <p>Thank you.</p> <p><strong>EDIT:</strong></p> <p>Perl Script:</p> <pre><code>#!/usr/bin/perl -w use strict; use warnings; my $file = $ARGV[0]; my $id = 0; open my $info, $file or die "Could not open $file: $!"; print "{"; while( my $line = &lt;$info&gt;) { print "\"$id\" : " . "\"" . trim($line) . "\""; print ',' unless eof; $id++; } print "}"; sub trim { (my $s = $_[0]) =~ s/^\s+|\s+$//g; return $s; } close $info; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload