Jump to content
xisto Community
Sign in to follow this  
renegade_division

How To Read Large Files In Php. Tutorial on reading large files in PHP.

Recommended Posts

First of all don't use file() function instead use fread() functions.
I think you should deploy the split-script technique. Its different
from splitting your text file. Instead you get two scripts to do the
same job.
Or you can deploy the following method.
First of all you should be knowing the size of the max text file which
can be read in the max_execution_time on your Web Server.
For that you need to use fread() function. with something like this:

$file=fopen("file.txt","r");$count=0;while(!feof($file)){$data=fread($file,1024);print($count+"<br>");flush();//flush it in betweenob_flush();//so that you get the count of max number of 1024 chunkssupported$count++;}
Now when the script crashes note down the count number and copy the
script where you used the file() function with some other name.
For example:
//file_proc.phpif(!isset($_GET['startcount'])&&!isset($_GET['startcount'])){$startcount=0;$endcount=$max_count_supported;//the number you took from the lastscript.}$file=fopen("file.txt","r");fseek($file,($endcount-$startcount)*1024);for($count=0;$count<=($endcount-$startcount);$count++){$data=fread($file,1024);//Process the data here}//Redirect the script to  file_proc.php?startcount=$endcount&endcount=($endcount+$max_supported_count)
I guess this should be getting the work done.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.