I am having a very strange problem with timeouts. I have a script that uploads a text file to be imported to the database which is anywhere from 4 to 8 megs in size. We have the max_execution_time set to 360 seconds and max_upload_size set to 10 meg, so there is theoreticaly plenty of time and space for the upload to occur.
However in some instances (certain machines have more trouble with this than others) when we are uploading the file we get a php fatal error that says we have hit the max execution time. However by watching the clock on Opera we only hit about a minute and a half....several minutes short of 360 seconds (6 minutes). Also by watching the progress meter on opera I can see that the entire file gets uploaded but emidiately after I get a timeout error.
A friend of mine writes in cold fusion and wrote a quick script to do a file upload which appears to work for clients that were timing out with the php script, so my question is what in the code could be causing the premature timeout.
-Many thanks
Andy
here is the error message:
Fatal error: Maximum execution time of 360 seconds exceeded in C:\Inetpub\webs\ctlgms\update\update_handle.php on line 4
and here is the code:
<?PHP
// update/update_handle.php
session_start();
include("../prepend.php");
//error checking
$_SESSION['errors'] = array();
if(empty($_POST['email'])) {
$_SESSION['errors'][] = "E-Mail cannot be left blank";
} else {
$email = clean($_POST['email'], 50);
}
if(empty($_POST['password'])) {
$_SESSION['errors'][] = "Password cannot be left blank";
} else {
$password = clean($_POST['email']);
}
$data_as_of = clean($_POST['data_as_of']);
if(empty($_POST['posted'])) {
$_SESSION['errors'][] = "Posted Date cannot be left blank.";
} else {
$posted = clean($_POST['posted']);
}
if(!is_uploaded_file($_FILES['file']['tmp_name'])) {
$_SESSION['errors'][] = "You must select a file to import from.";
}
//create random number to put on file name to ensure that things stay different
$seed = (float) microtime()* 100000000;
srand($seed);
$random = rand(1,25);
//move file to database directory
copy($_FILES['file']['tmp_name'], "C:\\mysql\\data\\ctlgms\\{$random}{$_FILES['file']['name']}");
$filename = $random .$_FILES['file']['name'];
if(count($_SESSION['errors']) > 0) {
header("Location: index.php");
exit;
}
//check access
//encrypt password
$salt = substr($email, 0, 2);
$password = crypt($_POST['password'], $salt);
//use SQL to authenticate
$sql = "SELECT t.town_id,
t.townname
FROM towns t,
update_users u
WHERE u.email = '{$email}'
AND u.passwd = '{$password}'
AND t.townname = u.townname";
$result = mysql_query($sql, $connection);
if(mysql_num_rows($result) != 1) { //unauthorized access
$_SESSION['errors'][] = "You are not authorized to preform this action,
please check your user E-Mail and password combination.";
header("Location: index.php");
exit;
}
//authorization complete
//update dates
$row = mysql_fetch_object($result);
$sql = "UPDATE towns
SET data_as_of = '{$data_as_of}',
posted = '{$posted}'
WHERE town_id = '{$row->town_id}'";
if(!@mysql_query($sql, $connection)) {
trigger_error("MySQL error " . mysql_errno() . ":" . mysql_error(), E_USER_ERROR);
}
//begin a transaction
mysql_query("START TRANSACTION", $connection);
//delete records for town in question
$sql = "DELETE FROM properties
WHERE town_id = '$row->town_id'";
if(!@mysql_query($sql, $connection)) {
mysql_query("ROLLBACK");
trigger_error("MySQL error " . mysql_errno() . ":" . mysql_error(), E_USER_ERROR);
exit();
}
//insert new records
$sql = "LOAD DATA INFILE '$filename'
INTO TABLE properties
FIELDS
TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'";
if(!@mysql_query($sql, $connection)) {
mysql_query("ROLLBACK");
trigger_error("MySQL error " . mysql_errno() . ":" . mysql_error(), E_USER_ERROR);
exit();
}
//sync up properties and towns databases
$sql = "UPDATE properties
SET town_id = '{$row->town_id}'
WHERE townname = '{$row->townname}'";
if(!@mysql_query($sql, $connection)) {
mysql_query("ROLLBACK");
trigger_error("MySQL error " . mysql_errno() . ":" . mysql_error(), E_USER_ERROR);
exit();
}
mysql_query("COMMIT");
//delete temp file
unlink("C:\\mysql\\data\\ctlgms\\{$filename}");
echo "Data imported successfuly";
?>