title: PHP, AJAX: large data being truncated
body: <h2>The Problem</h2>
  
  <p>I'm using jQuery to post a (relatively) large amount of data to a web system I am migrating from Ubuntu to CentOS (a painful process). The problem is that the data being received is truncated. Sending the same data from the server to the client results in no truncation.</p>
  
  <p>The amount of data being 'sent' (that is, what I'm seeing while debugging Javascript) is 116,902 bytes (the correct amount of data), whereas the amount of data being received is <strong>approximately</strong> 115,668 bytes: this number seems to vary, making me believe the problem may be time related. The transaction completes (receive, response) in approximately 3.1 seconds, not a huge amount of time. Are there any settings I should examine?</p>
  
  <p>That idea aside, my PHP installation is configured to accept 8M of post data and use to 128M of physical memory, which seems plenty enough.</p>
  
  <p>The jQuery code is below. I'm quite sure this isn't the problem, but I've included it as requested.</p>
  
  <p>Receiving:</p>
  
  <pre><code>function synchronise_down()
  {
      $.ajax({url: "scripts/get_data.php",
          context: document.body,
          dataType: "json",
          type: "POST",
          success: function(result)
              {
                  // Fix the state up.
                  update_data(result);
  
                  // Execute on syncronise.
                  execute_on_synchronise();
              },
          error: function(what, huh)
              {
                  IS_WAITING = false;
              }
          });
  }
  </code></pre>
  
  <p>Sending:</p>
  
  <pre><code>function synchronise_up()
  {
      var serialised = MIRM_MODEL.serialise();
      LAST_SERIALISED = new Date().getTime();
      $.ajax({url: "scripts/save_model.php",
          context: document.body,
          dataType: "json",
          data: {"model":serialised},
          type: "POST",
          success: function(result)
              {
                  // Fix the state up.
                  update_data(result, true);
  
                  // Execute on syncronise.
                  execute_on_synchronise();
              },
          error: function(what, huh)
              {
                  IS_WAITING = false;
              }
          });
  }
  </code></pre>
  
  <h2>Workaround (Wouldn't call this a solution)</h2>
  
  <p>Edit: I've 'fixed' this, but not necessarily found out what the problem is and how to solve it. It's an interesting problem so I'll describe my workaround and leave the question open.</p>
  
  <p>What I'm doing is rather than letting jquery handle the serialisation of my large data, I'm doing it myself first, essentially serialising twice. the code for this is as follows:</p>
  
  <pre><code>function synchronise_up()
  {
      var serialised = JSON.stringify(MIRM_MODEL.serialise());
      LAST_SERIALISED = new Date().getTime();
      $.ajax({url: "scripts/save_model.php",
          context: document.body,
          dataType: "json",
          data: {"model":serialised},
          type: "POST",
          success: function(result)
              {
                  // Fix the state up.
                  update_data(result, true);
  
                  // Execute on syncronise.
                  execute_on_synchronise();
              },
          error: function(what, huh)
              {
                  IS_WAITING = false;
              }
          });
  }
  </code></pre>
  
  <p>The important line is of course:</p>
  
  <pre><code>var serialised = JSON.stringify(MIRM_MODEL.serialise());
  </code></pre>
  
  <p>Now, when it hits the server, I need to decode this data because it's been serialised twice. There are added costs with this 'solution': sending more data, doing more work. The question still remains: what's the problem, and what's the real solution?</p>