Results 1 to 3 of 3

Thread: Memory Exhausted

  1. #1
    Join Date
    Nov 2009

    Memory Exhausted


    I am running an Ubuntu server and I have a file called update.php in the web directory.

    When I access the file with internet explorer on another computer on the local network, I get the following error:

    Fatal error: Allowed memory size of 104857600 bytes exhausted (tried to allocate 62 bytes) in /var/www/update.php on line 10

    The code in the file is below:-

    <?php$table = 'lookup';
    @mysql_select_db('cpg') or die("Unable to connect");
    $colheadings = 1;
    $deleterecords = "TRUNCATE TABLE '$table'";
    $filecontents=file("$table.csv"); # Line 10
    for($i=$colheadings; $i<sizeof($filecontents);$i++){$insertrecord = "Insert into '$table' Values ($filecontents[$i])";mysql_query($insertrecord);if(mysql_error()){$f ail+=1;}else{$pass += 1;}}echo "Fails = $fail and passes = $pass";

    When I first ran the program the error stated that the memory of 16mb were exhausted (tried to allocate 56mb). I changed the limit at /etc/php5/apache2/php.ini from 16mb to 128mb. I now get the error above.The csv file that I am accessing is about 60mb and is located on the server.Any thoughts would be greatly appreciated.


    Last edited by John_Needs_help; November 19th, 2010 at 01:33 PM. Reason: Make it look neater. Easier to read.

  2. #2
    Join Date
    Sep 2010

    Re: Memory Exhausted

    Loading that entire .csv file into an in-memory array will take a huge amount of memory. You could increase the memory limit further, or you change that script to process the file one line at a time.

    Or you could use the MySQL query LOAD DATA INFILE:

    Personally, I've found it easier to use the MySQL command line client when handling large amounts of data.

  3. #3
    Join Date
    Nov 2009

    Re: Memory Exhausted


    Thanks for your prompt reply and sound advice. I have used the load data infile and it is now working.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts