Re: CSV file
| From: | Richard Heyes | Date: | Thu, 25 Jun 2009 08:37:26 +0000 |
| Subject: | Re: CSV file | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-294568@lists.php.net to get a copy of this message | ||
Hi,
> Well, you are reading the whole file there (and throwing the data you
> read not assigning the fgets result to anything), and then to store it
> in the database you need to read it again, so you read the file twice.
> It will probably better to store the data you read the first time in
> an array and then store it in the database, that way you read it only
> once.
No, it's not. If the file is large then you could end up reading megs
into memory. If physical memory is low then the pagefile will come
into play and you'll get a lot of disk accesses. Reading 1 line at a
time is far more efficient and with larger files will be faster.
--
Richard Heyes
HTML5 graphing: RGraph (www.rgraph.net - updated 20th June)
PHP mail: RMail (www.phpguru.org/rmail)
PHP datagrid: RGrid (www.phpguru.org/rgrid)
PHP Template: RTemplate (www.phpguru.org/rtemplate)
PHP SMTP: http://www.phpguru.org/smtp