title: PHP: problem rendering large images (error 321)
body: <p>its me again with a php problem :)</p>
  
  <p>Following is part of my PHP script which is rendering JPEG images.   </p>
  
  <pre><code>...
  $tf=$requested_file;
  $image_type="jpeg";
  header("Content-type: image/${image_type}");
  $CMD="\$image=imagecreatefrom${image_type}('$tf'); image${image_type}(\$image);";
  eval($CMD);
  exit;
  ...
  </code></pre>
  
  <p>There is no syntactical error, because above code is working fine for small images, but for large images, it gives:</p>
  
  <p><code>Error 321 (net::ERR_INVALID_CHUNKED_ENCODING): Unknown error.</code> in the browser.</p>
  
  <p>To be sure, I created two images using imagemagick from same source image - one resized to 10% of original and other 90%.</p>
  
  <p><a href="http://mostpopularsports.net/images/misc/ttt10.jpg" rel="nofollow noreferrer">http://mostpopularsports.net/images/misc/ttt10.jpg</a>  works</p>
  
  <p><a href="http://mostpopularsports.net/images/misc/ttt90.jpg" rel="nofollow noreferrer">http://mostpopularsports.net/images/misc/ttt90.jpg</a>  gives Error 301 in the browser.</p>
  
  <p>There is a related question with solution posted by OP here <a href="https://stackoverflow.com/questions/3072759/error-writing-content-through-apache">Error writing content through Apache</a>   but I cannot understand how to make the fix. Can someome help me with it?</p>
  
  <p>I have looked at the headers in Chrome. For the first request, everything is fine. For the second request - the request headers are all garbled. </p>
  
  <hr>
  
  <p>Both images <em>are</em> jpeg (as they are created from imagemagick. But still to be sure I checked):</p>
  
  <pre><code>misc/ttt10.jpg: JPEG image data, JFIF standard 1.01
  misc/ttt90.jpg: JPEG image data, JFIF standard 1.01
  </code></pre>
  
  <hr>
  
  <p>Finally, the way I fixed is, remove the <code>Transfer-Encoding: chunked</code> header from the response. [This header was sent by apache only when the data was large enough]. (I had an internal proxy, so did it in the proxy script - otherwise one may need to do it in apache settings).</p>
  
  <p>There were some good answers and I have selected the one that helped me solve the problem best.</p>
  
  <p>thanks</p>
  
  <p>JP</p>