Form timeouts?

I’ve got a client that has a website that lets him add news articles through a special admin interface (using PHP and MySQL). The form that accepts these articles is a very basic form with a couple of text fields for the article title and category, and a large textarea field that accepts the body of the article. The article body may be quite large (30,000 characters isn’t unusual). The form is submitted using the POST method.

The client is complaining that when he fills in the article and submits the form that his browser appears to do nothing for a few minutes and then it comes back with a page not found error.

The server that is hosting the website is in Wellington, New Zealand. Everything appears to be working ok for me in Auckland, NZ. While the client was in NZ it worked fine, but now he is in Malaysia and the problem has started.

I’m thinking that it’s possible that his connection is slow and there is some sort of timeout happening somewhere. I assume that browsers only wait so long for a response after submitting a form and then give an error, is this correct? Is this timeout something that can be altered? Or is it possible that Apache has some sort of timeout and is closing the connection?

Can you post the code for the page is on and the code for the page that the user goes to after submit. Please wrap them in [ php ] tags (no spaces)

Here’s the code for the form page. It’s a PHP page that submits to itself so everything is self-contained. There’s an include at the top of the code that connects to the database and another that contains some utility functions for displaying errors and stuff like that.

<?php
require_once('../commonfunctions.inc.php');
require_once('../opendatabase.inc.php');

$errors = array();
$errorfields = array();
$has_errors = FALSE;

$action = isset($_POST['action']) ? $_POST['action'] : "";
if ($action <> "check") {
  $action = "display";
}

// Set up defaults
$title = "";
$section = "";
$body = "";

if ($action == "check") {
  // Tidy up the inputs
  foreach ($_POST as $key => $val) {
    if ($key <> 'body') {
      $tidyinput = TidyInput($val);
      $_POST[$key] = $tidyinput;
    }
  }

  $title = $_POST['title'];
  $section = $_POST['section'];
  $body = $_POST['body'];

  // Validate the inputs
  if ($title == "") {
    $errors[] = "Title must not be empty";
    $errorfields[] = "title";
  }
  if ($section == "") {
    $errors[] = "Project Section must not be empty";
    $errorfields[] = "section";
  }
  if ($body == "") {
    $errors[] = "Article must not be empty";
    $errorfields[] = "body";
  }

  if (count($errors) <> 0) {
    $has_errors = TRUE;
    $action = "display";
  } else {
    $action = "process";
  }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="Author" content="A Web 4 U Designs - www.aweb4u.co.nz">
<title>Project Civilization - Administration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../all.css">
</head>
<body>
<h3 align="center">Add an English Project Article</h3>
<?php
if ($action == "display") {
  if ($has_errors) {
    echo "<div class=\\"formerrors\\">";
    echo "<p class=\\"errorhighlight\\"><img src=\\"../images/warning.gif\\" width=\\"16\\" height=\\"16\\" align=\\"absmiddle\\"> Please correct the following errors:</p>";
    echo "<ul>";
    foreach($errors as $val) {
      echo "<li class=\\"errorhighlight\\">$val</li>";
    }
    echo "</ul>";
    echo "</div>";
  }
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="newsForm">
  <table border="0" cellpadding="2" cellspacing="1" align="center">
    <tr>
      <td align="right"><b>Title:</b></td>
      <td align="left"><input name="title" type="text" value="<?php echo $title; ?>" size="50" maxlength="100" <?php if (in_array("title",$errorfields)) echo "class=\\"fielderror\\""; ?>>
      </td>
    </tr>
    <tr>
      <td align="right"><b>Project Section:</b></td>
      <td align="left"><input name="section" type="text" value="<?php echo $section; ?>" size="50" maxlength="100" <?php if (in_array("section",$errorfields)) echo "class=\\"fielderror\\""; ?>>
    </tr>
    <tr>
      <td align="right" valign="top"><b>Article:</b></td>
      <td align="left"><textarea rows="15" name="body" cols="80" wrap="soft" <?php if (in_array("body",$errorfields)) echo "class=\\"fielderror\\""; ?>><?php echo $body; ?></textarea>
      </td>
    </tr>
    <tr>
      <td colspan="2" align="center"><input name="action" type="hidden" value="check">
        <input type="submit" value="Submit" name="submit">
      </td>
    </tr>
  </table>
</form>
<?php
}

if ($action == "process") {
  $id = md5(uniqid(rand()));  // Create a random ID value
  $section = mysql_real_escape_string($section);
  $title = mysql_real_escape_string($title);
  $body = mysql_real_escape_string($body);
  $sql = "INSERT INTO projects (ID,Section,Title,Body) VALUES ".
         "(\\"$id\\",\\"$section\\",\\"$title\\",\\"$body\\")";
  mysql_query($sql);
  if (mysql_error()) {
    DisplayMySQLError("Could not update Projects record",$sql,TRUE);
  }
?>
<p align="center">Project Article Added.</p>
<?php
}
?>
<p align="center"><a href="index.php">Back to Administration Menu</a></p>
</body>
</html>

My client has just tried inserting a small article consisting of just a few words and that went through ok, so it looks like the problem only happens when he tries to submit large articles.

I got the client to do a speed test between his current location and a server within NZ and it showed that he as getting about 500 kbps download and 244 kbps upload.

I’m wondering if a combination of a slow connection and sending a large volume of form data is tripping over a timeout value.

I see that PHP has a max_input_time value (currently set to 60 on my server) and I’ve got the max_execution_time left at the default of 30 seconds. Maybe increasing these values may fix the problem.

Even with the relatively slow connection, 30k chars isn’t a lot of data really, and shouldn’t approach any timeout. How long does it take to submit a similar article for yourself in NZ?
If your server is slow in general (both bandwidth and mysql/php performance) then his slow connection may aggravate the situation. If you know exactly when he performed erroneous operations, or his IP, you could possible look through the http error logs on the server for more information.

Submitting large articles within NZ takes only a second or so for 60,000 characters.

I’ve tried increasing max_input_time and max_execution_time to 300 seconds each but that hasn’t helped.

The client says there is a business center next door and he is going to try their internet connection to see if that is any better.