Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Fatal error: Allowed memory size

Posted on 2006-04-22
3
Medium Priority
?
726 Views
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).

0
Comment
Question by:ncw
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
limneos earned 2000 total points
ID: 16533260
try first to disable completely the memory limit and see if it works:

ini_set("memory_limit","-1");

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

ini_set("max_execution_time","120");

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

Try adding to your .htaccess file the lines:

RLimitMEM 50000000
0
 
LVL 1

Author Comment

by:ncw
ID: 16533511
Success!  ini_set("memory_limit","-1"); worked.

Fantastic, thank you.
0
 
LVL 1

Expert Comment

by:limneos
ID: 16533550
You're always welcome ;-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

581 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