Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT</strong> after update of question and <a href="https://stackoverflow.com/questions/3171155/least-memory-intensive-way-to-read-a-file-in-php/3171293#3171293">comments to answer of fabjoa</a>:</p> <p>There is definitely something fishy if a 700kb file eats up 140MB of memory with that code you gave (you could <code>unset</code> $relation at the end of the each iteration though). Consider using a debugger to step through it to see what happens. You might also want to consider rewriting the code to use <a href="http://de3.php.net/manual/en/splfileobject.fgetcsv.php" rel="nofollow noreferrer">SplFileObject's CSV functions</a> as well (<a href="http://de3.php.net/manual/en/function.fgetcsv.php" rel="nofollow noreferrer">or their procedural cousins</a>)</p> <p><a href="http://de3.php.net/manual/en/splfileobject.setcsvcontrol.php" rel="nofollow noreferrer">SplFileObject::setCsvControl example</a></p> <pre><code>$file = new SplFileObject("data.csv"); $file-&gt;setFlags(SplFileObject::READ_CSV); $file-&gt;setCsvControl('|'); foreach ($file as $row) { list ($fruit, $quantity) = $row; // Do something with values } </code></pre> <hr> <p>For an OOP approach to iterate over the file, try <a href="http://de3.php.net/manual/en/class.splfileobject.php" rel="nofollow noreferrer"><code>SplFileObject</code></a>:</p> <p><a href="http://de3.php.net/manual/en/splfileobject.fgets.php" rel="nofollow noreferrer">SplFileObject::fgets example</a></p> <pre><code>$file = new SplFileObject("file.txt"); while (!$file-&gt;eof()) { echo $file-&gt;fgets(); } </code></pre> <p><a href="http://de3.php.net/manual/en/splfileobject.next.php" rel="nofollow noreferrer">SplFileObject::next example</a></p> <pre><code>// Read through file line by line $file = new SplFileObject("misc.txt"); while (!$file-&gt;eof()) { echo $file-&gt;current(); $file-&gt;next(); } </code></pre> <p>or even </p> <pre><code>foreach(new SplFileObject("misc.txt") as $line) { echo $line; } </code></pre> <p>Pretty much related (if not duplicate):</p> <ul> <li><a href="https://stackoverflow.com/questions/2603807/how-to-save-memory-when-reading-a-file-in-php/2603923">How to save memory when reading a file in Php?</a></li> </ul>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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