Fatal error: Allowed memory size

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).

LVL 1
ncwAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

limneosCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ncwAuthor Commented:
Success!  ini_set("memory_limit","-1"); worked.

Fantastic, thank you.
0
limneosCommented:
You're always welcome ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.