File() too slow

This is a discussion on File() too slow within the PHP Language forums, part of the PHP Programming Forums category; I am trying to process a CSV file but am having trouble with my hosts maximum execution time of 30 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-26-2003
RG
 
Posts: n/a
Default File() too slow

I am trying to process a CSV file but am having trouble with my hosts
maximum execution time of 30 seconds.
This is how the script works at the moment.
User uploads their CSV file
The script goes through the file() and writes smaller chunk files.
The script then goes through processing the smaller files, populating the
database, deleting the processed file and refreshing itself, thus starting
again.

This system works for files up to 15000 rows, but I need to be able to
process larger files.
The bottleneck is with the initial splitting, since I use the file()
function to read the entire uploaded file.

Does anyone know a quicker way to split a file into smaller chunks.

TIA
RG



Reply With Quote
  #2 (permalink)  
Old 09-26-2003
Timo Henke
 
Posts: n/a
Default Re: File() too slow

> This system works for files up to 15000 rows, but I need to be able to
> process larger files.
> The bottleneck is with the initial splitting, since I use the file()
> function to read the entire uploaded file.


file() is by far NOT a bottleneck at your present Problem as it is not
any slower than reading the using fread() and splitting it up afterwards.

The Bottleneck is (seems like) your Database compare / writing stuff.

It sounds like you read in eg. 15000 lines, break them down into chunks
and then proceed all the chunks line by line, checking the database,
comparing
the database data with your cvs and then deciding on what to do (delete,
insert
update ...)

At 15000 Entries THIS will make your Script timeout, not the file()
command.

If you do not believe it, try to manually read and explode it ...

regards

timo

Reply With Quote
  #3 (permalink)  
Old 09-26-2003
RG
 
Posts: n/a
Default Re: File() too slow


"Timo Henke" <webmaster@fli7e.de> wrote in message
news:bl0qhl$r0u$06$1@news.t-online.com...
> > This system works for files up to 15000 rows, but I need to be able to
> > process larger files.
> > The bottleneck is with the initial splitting, since I use the file()
> > function to read the entire uploaded file.

>
> file() is by far NOT a bottleneck at your present Problem as it is not
> any slower than reading the using fread() and splitting it up afterwards.
>
> The Bottleneck is (seems like) your Database compare / writing stuff.
>
> It sounds like you read in eg. 15000 lines, break them down into chunks
> and then proceed all the chunks line by line, checking the database,
> comparing
> the database data with your cvs and then deciding on what to do (delete,
> insert
> update ...)
>
> At 15000 Entries THIS will make your Script timeout, not the file()
> command.
>
> If you do not believe it, try to manually read and explode it ...
>
> regards
>
> timo
>



The initial splitting of the file is the bottleneck, I do not compare
anything in this procedure.
There is not a problem with the database comparing etc, it seems to take
about 2 seconds to do around 3000 mysql queries. This is fine.

I just need a quick way to initially split the large file into smaller
files.
TIA
RG



Reply With Quote
  #4 (permalink)  
Old 09-26-2003
Timo Henke
 
Posts: n/a
Default Re: File() too slow

> The initial splitting of the file is the bottleneck, I do not compare
> anything in this procedure.
> There is not a problem with the database comparing etc, it seems to take
> about 2 seconds to do around 3000 mysql queries. This is fine.


lets talk about filesizes. I JUST tried it. Reading (and splitting) a 19MB
File
with 322000 Lines took 0.39843 seconds on My Machine:


<?php

list($usec, $sec) = explode(" ",microtime());
$start =((float)$usec + (float)$sec);

$indata = file("cvs");

list($usec, $sec) = explode(" ",microtime());
$end =((float)$usec + (float)$sec);

printf("%.5f",$end-$start);

?>

This IS NOT a bottleneck i believe?

Timo

Reply With Quote
  #5 (permalink)  
Old 09-26-2003
RG
 
Posts: n/a
Default Re: File() too slow


"Timo Henke" <webmaster@fli7e.de> wrote in message
news:bl0rja$ul9$05$1@news.t-online.com...
> > The initial splitting of the file is the bottleneck, I do not compare
> > anything in this procedure.
> > There is not a problem with the database comparing etc, it seems to take
> > about 2 seconds to do around 3000 mysql queries. This is fine.

>
> lets talk about filesizes. I JUST tried it. Reading (and splitting) a 19MB
> File
> with 322000 Lines took 0.39843 seconds on My Machine:
>
>
> <?php
>
> list($usec, $sec) = explode(" ",microtime());
> $start =((float)$usec + (float)$sec);
>
> $indata = file("cvs");
>
> list($usec, $sec) = explode(" ",microtime());
> $end =((float)$usec + (float)$sec);
>
> printf("%.5f",$end-$start);
>
> ?>
>
> This IS NOT a bottleneck i believe?
>
> Timo
>


Lightning fast.
I think I've found the problem: upload_max_filesize is 2M
It is dieing, very poorly.
You must have changed your php.ini?
Thanks for the pointers
RG


Reply With Quote
  #6 (permalink)  
Old 09-26-2003
Timo Henke
 
Posts: n/a
Default Re: File() too slow

> Lightning fast.

yeehaa :-)

> I think I've found the problem: upload_max_filesize is 2M
> It is dieing, very poorly.
> You must have changed your php.ini?


jupp .. changed to 32M, because i often need to transfer bigger
data in our intranet.

> Thanks for the pointers


hope it would work out well for you

regards

timo

Reply With Quote
  #7 (permalink)  
Old 09-26-2003
RG
 
Posts: n/a
Default Re: File() too slow


"Timo Henke" <webmaster@fli7e.de> wrote in message
news:bl0so7$vl4$05$1@news.t-online.com...
> > Lightning fast.

>
> yeehaa :-)
>
> > I think I've found the problem: upload_max_filesize is 2M
> > It is dieing, very poorly.
> > You must have changed your php.ini?

>
> jupp .. changed to 32M, because i often need to transfer bigger
> data in our intranet.
>
> > Thanks for the pointers

>
> hope it would work out well for you
>
> regards
>
> timo
>


I don't suppose there's a workaround for this?
RG


Reply With Quote
  #8 (permalink)  
Old 09-26-2003
RG
 
Posts: n/a
Default Re: File() too slow


"Timo Henke" <webmaster@fli7e.de> wrote in message
news:bl0so7$vl4$05$1@news.t-online.com...
> > Lightning fast.

>
> yeehaa :-)
>
> > I think I've found the problem: upload_max_filesize is 2M
> > It is dieing, very poorly.
> > You must have changed your php.ini?

>
> jupp .. changed to 32M, because i often need to transfer bigger
> data in our intranet.
>
> > Thanks for the pointers

>
> hope it would work out well for you
>
> regards
>
> timo
>


I don't suppose there's a workaround for this?
RG


Reply With Quote
  #9 (permalink)  
Old 09-26-2003
Eto Demerzel
 
Posts: n/a
Default Re: File() too slow

In article <3f73f748$0$65579$65c69314@mercury.nildram.net>, RG's output
was...
> > > I think I've found the problem: upload_max_filesize is 2M
> > > It is dieing, very poorly.
> > > You must have changed your php.ini?

> >
> > jupp .. changed to 32M, because i often need to transfer bigger
> > data in our intranet.

>
> I don't suppose there's a workaround for this?
> RG
>

IIRC - you can do something along the lines of:

ini_set("upload_max_filesize", "64M");


- I understand this will only change the max size for operations in that
particular script - not for the whole server/virtual server.
Reply With Quote
  #10 (permalink)  
Old 09-26-2003
RG
 
Posts: n/a
Default Re: File() too slow


"Eto Demerzel" <eto.demerzel@fijivillage.com> wrote in message
news:MPG.19de0adf1903d3b498971b@news-text.blueyonder.co.uk...
> In article <3f73f748$0$65579$65c69314@mercury.nildram.net>, RG's output
> was...
> > > > I think I've found the problem: upload_max_filesize is 2M
> > > > It is dieing, very poorly.
> > > > You must have changed your php.ini?
> > >
> > > jupp .. changed to 32M, because i often need to transfer bigger
> > > data in our intranet.

> >
> > I don't suppose there's a workaround for this?
> > RG
> >

> IIRC - you can do something along the lines of:
>
> ini_set("upload_max_filesize", "64M");
>
>
> - I understand this will only change the max size for operations in that
> particular script - not for the whole server/virtual server.



Tried that out but it seems that the file is uploaded before the script is
executed which means, the file is dumped before the function is called.
I'm sure my host wont want to change these settings, Rackshack (cheap).
Looks like I'm gonna have to get some more expensive hosting.
Any suggestions: PHP with GD, Multiple MySQL databases, password protect
directories, 20gb month
Thanks
RG



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:08 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0