Jump to content

time out on CSV file


djanim8

Recommended Posts

right now I have a CSV file that I'm having users upload and insert the data into a mySQL database..

 

the file (at this time, it will get bigger and bigger) has over 11,000 lines in it..

 

The page continually times out.. right now I have the timeout set:

 

set_time_limit(3600);

 

it always gives me a CGI error when it gets about 3/4 the way through it... no matter how long I set the the set_time_limit to..

 

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers.

 

does anyone have any suggestions on how to fix this?

Link to comment
Share on other sites

here is all the code if it helps:

 

				
set_time_limit(3600);

$handler = fopen($_FILES['fleMusicCSV']['tmp_name'],'r'); 
$addCount = 0;
$totCount = 0;
$existsCount = 0;

if($_POST['chkDelete'] <> "") {
$mySQL = "DELETE FROM songs";
$deleteResults = mysql_query($mySQL);
$songID = 0;
} else {
$mySQL = "SELECT * FROM songs ORDER BY songID DESC";
$getResults = mysql_query($mySQL);
$songRow = mysql_fetch_array($getResults);
$songID = $songRow['songID'];
}

while ($row = fgetcsv($handler,1024,",","")) {
$artist = $row[0];
$title = $row[1];
$genre1 = $row[2];
$genre2 = $row[3];
$disc = $row[4];
$track = $row[5];
$firstDance = $row[6];
$brideFather = $row[7];
$groomMother = $row[8];
$couplesDance = $row[9];
$boquet = $row[10];
$garter = $row[11];

$songID++;
$mySQL = "INSERT INTO songs (songID,artist,title,genre1,genre2,disc,";
$mySQL .= "track,firstDance,brideFather,groomMother,couplesDance,boquet,garter";

$mySQL .= ") VALUES (";

$mySQL .= "'".$songID."','".$artist."','".$title."','".$genre1."','".$genre2."','".$disc."','";
$mySQL .= $track."','".$firstDance."','".$brideFather."','".$groomMother."','".$couplesDance."','".$boquet."','".$garter."')";

$uploadResult = mysql_query($mySQL);

if($uploadResult) {
	$addCount++;
} else {
	echo "There is something wrong on row ".$totCount." and I can't insert this record into the database!<br>";
}
echo "";

$totCount++;
} 
fclose($handler); 

Link to comment
Share on other sites

I also facing this problem before. I solved it by changing MySQL query. Change the query

 

fom:

INSERT INTO songs (songID,artist,title,genre1,genre2,disc,track,firstDance,brideFather,groomMother,couplesDance,boquet,garter) VALUE (..., ..., .....)

 

INSERT INTO songs (songID,artist,title,genre1,genre2,disc,track,firstDance,brideFather,groomMother,couplesDance,boquet,garter) VALUE (..., ..., .....)

 

..

 

 

to:

 

INSERT INTO songs (songID,artist,title,genre1,genre2,disc,track,firstDance,brideFather,groomMother,couplesDance,boquet,garter) VALUE (..., ..., .....), (..., ..., .....), (..., ..., .....),(..., ..., .....)

 

 

 

Hope this can help.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.