The slow function is getimagesize. It's a PHP library function and it can take as long as 15 seconds to return for the large image that's causing problems. Most images parse faster, but the call was probably always there. I suspect one of two things happened:
1) The timeout on the SQL database was lessened (15s seems a little short)
2) Something about this image is abnormal as far as being parsed by getimagesize. The delays are additive, so will likely encounter a similar error by including lots of images in your post (an average-size image takes a little less than 1s to parse)
Well, a browser knows an image's size even before it's downloaded the whole image, right? I figured that there had to be some way for PHP to do the same, and when going through the comments on PHP.net's
getimagesize documentation, I found
a possible solution for JPEGs. It does what I assume most browsers do: it goes through a JPEG's data until it finds the header bytes that specify its resolution.
If anyone here knows PHP and also knows how other image formats (BMP, PNG, GIF) are structured, then they can write similar functions, effectively removing the need for
getimagesize.
None.
I think these are correct:
Bitmap dimensions:
- offset 12: width
- offset 16: height
GIF dimensions:
- offset 06: width
- offset 08: height
(Those are hex values.)
None.
The slow function is getimagesize. It's a PHP library function and it can take as long as 15 seconds to return for the large image that's causing problems. Most images parse faster, but the call was probably always there. I suspect one of two things happened:
1) The timeout on the SQL database was lessened (15s seems a little short)
2) Something about this image is abnormal as far as being parsed by getimagesize. The delays are additive, so will likely encounter a similar error by including lots of images in your post (an average-size image takes a little less than 1s to parse)
Well, a browser knows an image's size even before it's downloaded the whole image, right? I figured that there had to be some way for PHP to do the same, and when going through the comments on PHP.net's
getimagesize documentation, I found
a possible solution for JPEGs. It does what I assume most browsers do: it goes through a JPEG's data until it finds the header bytes that specify its resolution.
If anyone here knows PHP and also knows how other image formats (BMP, PNG, GIF) are structured, then they can write similar functions, effectively removing the need for
getimagesize.
I believe almost all image formats have resolution data inside of the file, usually very close to the top. That code should be easily modifiable, especially on well know formats like BMP and GIF, which you can find large amounts of documentation about online. Same probably goes for PNG and just about any other format you could think of. I'll see if I can look into it a bit tommorrow.
None.