Problem with fclose and md5_file func

0k.a.b.a0

Verified User
Joined
Dec 8, 2008
Messages
20
Hello,

Several of my users told me about the problem with the fclose() function of php. They gave me a small php script which shows that the function works only for the second time. Since my users are using a function md5_file() in their scripts, the results they are not loyal to. This is a serious problem that I can not decide. Server software: OS FreeBSD 7.1, apache 2.2 + php 5.2.10 (installed through custombuild)

php script example:
PHP:
<? 
    function curl_redir_exec($ch) 
    { 
        static $curl_loops = 0; 
        static $curl_max_loops = 20; 
        if ($curl_loops++ >= $curl_max_loops) 
        { 
            $curl_loops = 0; 
            return FALSE; 
        } 
        curl_setopt($ch, CURLOPT_HEADER, true); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        $data = curl_exec($ch); 
        list($header, $data) = explode("\n\n", $data, 2); 
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
        if ($http_code == 301 || $http_code == 302) 
        { 
            $matches = array(); 
            preg_match('/Location:(.*?)\n/', $header, $matches); 
            $url = @parse_url(trim(array_pop($matches))); 
            if (!$url) 
            { 
                //couldn't process the url to redirect to 
                $curl_loops = 0; 
                return $data; 
            } 
            $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL)); 
            if (!$url['scheme']) 
                $url['scheme'] = $last_url['scheme']; 
            if (!$url['host']) 
                $url['host'] = $last_url['host']; 
            if (!$url['path']) 
                $url['path'] = $last_url['path']; 
            $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($ 
            curl_setopt($ch, CURLOPT_URL, $new_url); 
            return $new_url; 
        } else { 
            $curl_loops=0; 
            return $data; 
        } 
    } 


echo md5_file('icq.gif').' : 1<br>'; //1 
$icq_link=curl_init("http://status.icq.com/online.gif?icq=53907547&img=27"); 
$icq_file=fopen('icq.gif', 'w'); 
$url_link=curl_redir_exec($icq_link); 
echo $url_link."<br />"; 
$icq_link=curl_init("$url_link"); 
curl_setopt($icq_link, CURLOPT_FILE, $icq_file); 
curl_setopt($icq_link, CURLOPT_HEADER, 0); 
curl_exec($icq_link); 
curl_close($icq_link); 
$result=fclose($icq_file); 

echo "Fclose result: ".$result."<br />"; 
echo md5_file('icq.gif').' :2<br>'; //1 
$icq_file=fopen('icq.gif', 'r'); 
echo md5_file('icq.gif').' :3<br>'; //1 
$result=fclose($icq_file); 
echo "Fclose result: ".$result."<br />"; 
echo md5_file('icq.gif').' :4<br>'; 
?>

Result:
Code:
57349976dfb9ff183c2fd69907e0b16f : 1
http://status.icq.com/27/online1.gif
Fclose result: 1
d41d8cd98f00b204e9800998ecf8427e :2
57349976dfb9ff183c2fd69907e0b16f :3
Fclose result: 1
57349976dfb9ff183c2fd69907e0b16f :4

Also, I checked the script work on another server, that is running OS FreeBSD 7.1 and apache 2.0 + php 5.2.9 installed from ports collection. And I don't have any problems with script work on this server.

Anybody has faced this problem and whether there was a problem on servers with linux OS?

Thx.
Ihor R.
 
Back
Top