A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearHow to get the total number of rows before reading in a large file in PHP - page 1
User InfoPosts
How to get the total number of rows before reading in a large file in PHP#1
I am already using this example of how to read large data files in PHP line by line

Now, what it(d like to do, is obtain the total number of rows in the file so that I may display a percentage complete or at least what the total number of rows are so I can provide some idea of how much processing is left to be done.

Is there a way to get the total number of rows without reading in the entire file twice? (once to count the rows and once to do the processing)

posted date: 2009-04-15 10:28:00


Re: How to get the total number of rows before reading in a large file in PHP#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-15 10:28:01


Re: How to get the total number of rows before reading in a large file in PHP#3
Poor mans answer:No, but you can estimate. Calc a simple average reading (use the first 250 lines) and go with that. estNumOfLines = sizeOfFile / avgLineSizeYou could store off the number of lines in the file when you are creating the file...Alternatively, you could display the number of KB processed, and that would be perfectly accurate.

posted date: 2009-04-15 10:30:00


Re: How to get the total number of rows before reading in a large file in PHP#4
How would you know the number of pages in a book, without counting them?You would measure the width of a page and the width of the book and divide one by the other.Same here, calculate the average line length from the first few lines, then do the same math with the file size...

posted date: 2009-04-15 10:32:00


Re: How to get the total number of rows before reading in a large file in PHP#5
Is there any reason you need to count rows and not bytes? If all you want to know is "percent done", just track it the by number bytes read/total bytes.

posted date: 2009-04-15 10:33:00


Re: How to get the total number of rows before reading in a large file in PHP#6
+1 for your bolded suggestion (the only reasonable approach, IMO)

posted date: 2009-04-15 10:34:00


Re: How to get the total number of rows before reading in a large file in PHP#7
The processing is going to be done on a very large third party product file on a line by line(product by product) basis.

posted date: 2009-04-15 10:36:00


Re: How to get the total number of rows before reading in a large file in PHP#8
Wow, we have some serious quick-draw php peeps here...thanks guys!

posted date: 2009-04-15 10:37:00


Re: How to get the total number of rows before reading in a large file in PHP#9
+1 for the code :)

posted date: 2009-04-15 10:38:00


Re: How to get the total number of rows before reading in a large file in PHP#10
I vote for just displaying the amount of data processed. Would probably be the best solution.

posted date: 2009-04-15 10:42:00


Re: How to get the total number of rows before reading in a large file in PHP#11
page size is constant. line width and bytes with utf-8 (or similar) special chars is not.

posted date: 2009-04-15 12:12:00


Re: How to get the total number of rows before reading in a large file in PHP#12
use the byte by byte suggested by vezult

posted date: 2009-04-15 12:13:00


select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.