I am trying to read the content of a file whose size is 84987931 bytes with a php function file(); It is giving error : Fatal error: Allowed memory size of 83886080 bytes exhausted (tried to allocate 4097 bytes) in "filepath/index.php" on line no 7. I have tried with this code too : $handle = @fopen('file_path', "r"); if ($handle) { while (!feof($handle)) { $lines[] = fgets($handle, 4096); } fclose($handle); } But the same error is giving. Any one know any function so I can read a long file any how. Thanks in advance for any help Subikar Burman
It seems a limitation set by your hosting company. Do you really need to read the file completely before to process ? How about processing while reading ?, that's inside your while loop.
After few minutes it is giving error what I mention in my first post. Is there any solution ? or function I can read it?
I beleive you can modify this option in the php.ini file, I cant remember what the actual command is, but im sure google will relish some answers.
If he can gain access to php.ini file, then it can be modified to increase the memory limitation. If not, then it is down to the hosting company to modify that for him.
Is it possible for doing it from programming site. Actually I don't want to do any change in php.ini. If it is possible to do by any php coding then it can be helpful.
You can find several examples of managing large files on this page: http://es.php.net/fgets I like the code from hackajar on that page, however probably you don't need a buffer so huge (16Mb).
What are you trying to do with the file? Your best bet is to probably read it in chunks with a while() loop. If need-be you can store it in a database for processing, but I can't think of any reason you'd really need to handle the entire chunk of data at a time.
Asking your host to increase your memory limit will only work until you run into another file that's even larger than *that* limit. As a couple people have said, the clever solution to this problem is to process the file in chunks. There is some sample code in this thread that might help you: http://forums.digitalpoint.com/showthread.php?t=325513
use ini_set() function to change the file size limitation.but there is a problem.u have to set the php.ini to change its setting by using ini_set().so anyhow u have to change php.ini
OK guys I got the option $ic and ic_max and within this two range I am using fgets() and fetching the data. Thanks a lot for you all kind cooperation. Thanks again