I have a file with around 269 thousand lines. The size of the file is around 500MB. I want to read the file on localhost but it says the memory is not enough. Then i try to run it in my web server, but when i run my program it didn't display anything, then my browser crashed. Can anyone help me?
Asked
Active
Viewed 40 times
0
-
1I bet your code is not Object Oriented. to deal with kind of huge file you need to use OOP – Aniruddha Chakraborty Dec 10 '15 at 07:20
-
If you are not using OOP than try to optimize your queries, make indexes, avoid unnecessary php functions and move your code in different function than it be easy to optimize flat code. – devpro Dec 10 '15 at 07:22
-
I assume that your code does not work since you try to load the whole file into memory at once to process it. That means the memory consumption will be even higher, since you additionally copy parts of it for processing. The solution for this is to change your code such that the file is only read bit by bit whilst getting processed. That keeps a small memory footprint, your code will scale regardless of the size if the file. I know this is vague, but we cannot say more without you posting your code here. – arkascha Dec 10 '15 at 07:24
-
1@AniruddhaChakraborty you can program with a small footprint in procedural programming style too, actually it is much easier that in OOP style. Just remember back in time when RAM was measured in KBytes on big machines, OOP didn't even exist in that time. – arkascha Dec 10 '15 at 07:25
-
2Have a look at these questions which possibly have a solution for you : http://stackoverflow.com/questions/3171155/least-memory-intensive-way-to-read-a-file-in-php and http://stackoverflow.com/questions/2603807/how-to-save-memory-when-reading-a-file-in-php/2603923 – Madhu V Rao Dec 10 '15 at 07:34