title: Apache crashes in a large foreach loop on an associative array in PHP
body: <p><strong>EDIT</strong>: In response to Robus' answer I tried to run the PHP script from command line. This is the result:</p>
  
  <p><img src="https://i76.photobucket.com/albums/j37/dahwan/Capture-5.png" alt="CLI crash"></p>
  
  <p>But interestingly; an echo statement that was located <strong>after</strong> the <code>foreach</code> loop in my code output it's text to the console window. Thus I can only assume that CLI crashes at the conclusion of / after running the script.</p>
  
  <hr>
  
  <p>I have a script which function is to load all rows from an XLSX file into a MySQL table. I am using PHPExcel for this. I wrote the function <code>loadFromXLS</code> to load the data from the XLSX file and return a two dimensional array with the data. In this particular case that means 3100 rows and 29 columns.</p>
  
  <p>This is the function:</p>
  
  <pre><code>function loadFromXLS($filepath)
  {
      $retval = array();
      $cols = array();
      $rownum = 0;
  
      $reader = PHPExcel_IOFactory::createReaderForFile($filepath);
      $reader-&gt;setReadDataOnly(true);
  
      $phpObject = $reader-&gt;load($filepath);
      $sheet = $phpObject-&gt;getActiveSheet();
  
      foreach($sheet-&gt;getRowIterator() as $row)
      {
          $celliterator = $row-&gt;getCellIterator();
          $celliterator-&gt;setIterateOnlyExistingCells(false);
          $cellnum = 0;
  
          foreach($celliterator as $cell)
          {
              if($rownum === 0)
              {
                  $cols[$cellnum] = $cell-&gt;getValue();
              }
              else
              {
                  if(is_array($retval[$rownum-1]))
                      $retval[$rownum-1] += array($cols[$cellnum] =&gt; $cell-&gt;getValue());
                  else
                      $retval[$rownum-1] = array($cols[$cellnum] =&gt; $cell-&gt;getValue());
              }
  
              $cellnum++;
          }
  
          $rownum++;
      }
  
      unset($reader, $phpObject, $sheet);
  
      return $retval;
  }
  </code></pre>
  
  <p>The top row of the file is the column names.</p>
  
  <p>In any case, I have confirmed that it loads the data correctly by <code>var_dump</code>ing the first few rows and checking the array length.</p>
  
  <p>This is the problem. As soon as I add this line:</p>
  
  <pre><code>foreach($data as $i =&gt; $row) {};
  </code></pre>
  
  <p>Apache simply crashes when it gets to that point:</p>
  
  <p><img src="https://i76.photobucket.com/albums/j37/dahwan/Capture-4.png" alt="Apache crash"></p>
  
  <p><strong>So what's up with that? Can't PHP handle loops through large associative arrays? Any explanatory answers would be appreciated. Please comment if there is additional information I can provide</strong></p>
  
  <hr>
  
  <p><em>I'm running XAMPP on Windows 7, Intel i5 processor, 4GB RAM. I have increased <code>memory_limit</code> in php.ini to 512MB which is more than enough (It used to give me a memory error when it was set to 128MB). This script includes PHPExcel.php and dBug.php. The two dimensional array is only filled with strings, no funky PHPExcel datatypes.</em></p>
  
  <p><em>I'm running PHP version 5.3.1</em></p>
  
  <p><em>Loaded modules: core mod_win32 mpm_winnt http_core mod_so mod_actions mod_alias mod_asis mod_auth_basic mod_auth_digest mod_authn_default mod_authn_file mod_authz_default mod_authz_groupfile mod_authz_host mod_authz_user mod_cgi mod_dav mod_dav_fs mod_dav_lock mod_dir mod_env mod_headers mod_include mod_info mod_isapi mod_log_config mod_mime mod_negotiation mod_rewrite mod_setenvif mod_ssl mod_status mod_autoindex_color mod_php5 mod_perl mod_apreq2</em></p>
  
  <p><a href="http://i76.photobucket.com/albums/j37/dahwan/Capture-6.png" rel="nofollow noreferrer">phpinfo() screenshot</a></p>