php: timeouting getimagesize for broken image links
web October 7th, 2008
Today while i was working on mmofresh.com, somehow the code was running strange. After inspecting it became out that an image link from feeds was broken and the getimagesize function of php was waiting for it ~60 seconds.
So using the php manual’s help i added this piece of code before getimagesize call, which checks image link using fopen with a given timeout of 3 seconds.
// check image with fopen to ensure we don’t wait quite long
$timeout = 3;
$old = ini_set(’default_socket_timeout’, $timeout);
$fp = @fopen($src, ‘r’);
ini_set(’default_socket_timeout’, $old);if (!$fp) // timed out
return False;
Tags: fopen, getimagesize, php, timeout
About