Fatal error: Allowed memory size

Posted on 2006-04-22
Last Modified: 2012-06-21
I'm using a php script to open and read a data file using function fgetcsv; this works for data files up to the size of about 6MB but fails with a file of 7.98MB. I realise the default memory_size is 8MB and I'm wanting to open a 22MB text data file on the webserver. I've tried increasing the memory_size using both of the following techniques:

ini_set("memory_limit","50M");  -  placed at the top of the script file

php_value memory_limit "50M"  - placed in an .htaccess file

Both of these methods seem to cause the error message to register the increase, but it still fails. A typical error message:

Fatal error: Allowed memory size of 52428800 bytes exhausted (tried to allocate 31 bytes) in /home/account/public_html/directory/functions.php on line 117

Looking for some specific advice please, not links to other questions unless they have info specific to my problem. Maybe there's a better way to read the csv file, or read it in stages (line by line would take a long time there's 15000 records).

Question by:ncw
    LVL 1

    Accepted Solution

    try first to disable completely the memory limit and see if it works:


    also set the max_execution_time to ...say 120 seconds to make sure there's enough time to parse the code:


    There is also a case where Apache's memory limit interferes here .

    Try adding to your .htaccess file the lines:

    RLimitMEM 50000000
    LVL 1

    Author Comment

    Success!  ini_set("memory_limit","-1"); worked.

    Fantastic, thank you.
    LVL 1

    Expert Comment

    You're always welcome ;-)

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Join & Write a Comment

    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    The viewer will learn how to dynamically set the form action using jQuery.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now