Friday, November 04, 2005

squid error while Uploading Image with PHP

I have a very strange problem with Squid on a host provided by a company in vienna. While triing to upload an Image with HTTP Post (normal Form Element with input File) i get a

Zero Sized Reply

ErrorMessage from Squid. The Problem only occures only when using Images greather than 1MB.

At first we checked the Parameters for php and apache (post_max_size,..) but they were set at least at 16MB... So this is not the source of our problems.

I have to clarify one thing: The Image normally would be uploaded, resized and then saved. Becouse of the Problems i changed the upload to first upload the image to a temporary File and then work with it, same Problem, but the File has been uploaded before the Error occured.

That made me a little curious and i checked the code where the Error exactly happen to be...
Another little Info is required here:
  • First i upload the File, which works fine.
  • Then i create an object from that image, which happens to be in jpeg Format, so i use imagecreatefromjpeg.
  • After that i have some code for resizing the image and
  • then i create a new Image Object by using imagecreatetruecolor with the calculated Size and copy the image into that new Object
  • At last the Object is saved as a File.
Well i used some var_dumps and exits and found the point where everything stopped working.. imagecreatetruecolor.

Odd, i though, and tried to create a Image with a less size... worked perfectly. Then i aligned the size step by step to the one calculated... and at about 300x200 there was the end.

Ok, this meant for me: The Function has not enough Memory to acquire for the Image.. The Provider also worked on the Problem on their site and they have another Problem: It works Perfectly on their site... why is it working when they are triing and when i try it not?
They asked me to outsource the code to a single file for testing, which i did. I tested it myself first and wow, everything is working...

Now i thought: That's it, here it ends, i am completely at the end of my knowledge and went home for some sleep ;-)

The next day i thought over it again and found the reason.. i used a couple of classes for the System, which i did not use on the outsourced File. This classes also needed some Memory which now they don't, so i have more memory for the Upload.
The quickest test was to change the end Resolution to 800x600, which worked on the server at my work fine, but not on the other host. (Got Ya!)

I simplified the outsourced code, killed the calculation code (since the end Size is 800x600) and so on until i just had the basic part. While working on that i found out if i don't call session_start() at the end of the file, the Code also stopps at the same position, but no error Message was called... (no Zero Sized Reply)...

Now we are still searching for that error.

No comments: