![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Posts: 54
Rep Power: 3
![]() |
Question on files
Hi,
I am using PHP to make a website related to biology. In this site I use PHP code to communicate with external programms (not in PHP, but some biological packages). These programms write their output in temporary files, which I then read using fread() or file_get_contents() functions. My problem is that these functions seem to have a restriction as to the size of the file that they can read. Is there any other way I read big files (for files close to 20-30MBs for example)? Please note that there is no other way for me to do this because these programs, by default, write their output to a text file, so I can't use PHP's system commands and read the output on the fly. The output file is first created and then I read it into a string and parse it according to what I need. |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
File or file_get_contents try to read the whole shootin' match in one fell swoop. Using fread, you can read however much you can handle, dispose of it, and go back for more (from the same input file). Believe me, when external storage sources were stretched to handle a couple hundred K, the problem was solved. I doubt you could eat a cow with one bite, but I 'magine you handle your steaks jes' fine.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() ![]() |
I had a similar issue last night in PHP. I was reading in large images and my script was only allowed 8mb max so it gave me errors that referred me to increasing the memory limit in PHP.
In /etc/php.ini (assuming you are running linux) search for memory_limit and change 8M (default) to 32M. [PHP] memory_limit = 32M [/PHP] This may help.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Assuming also that you're talking your own installation
.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() ![]() |
Indeed
![]()
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#6 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
As DaWei said, it would be best if you parsed the information in chunks. While I've never used these packages you speak of, I doubt all the data needs to be processed at once. So just read until you hit some sort of separator, deal with that bit (store it in your database or whatever), discard it and move onto the next. Play nice with your server - I'm sure its RAM could be used for much more useful purposes.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|