Hello,

I am having a problem with fopen on ONE of my servers. It works fine on all my other ones.

When i try to open a url in fopen, to check if it exists or not, it always returns true. It doesnt register the 404 like its supposed to.

Here is the test file i am using:

I have this file reading the stream of fopen and outputting it to the browser.

http://pvt-test.tooshocking.com/fopentest.php

If you notice it just grabs the 404 page instead of returning an error like the same code does on this server

http://media2.evilchili.com/adengage/fopentest.php

I can't find any information on why this would be doing this.

Can anyone here help me fix this?
here is the code i am using to test

	
<?php

$fp = fopen("http://media2.evilchili.com/content/blogs/pictures/Desert%20Landscape.jpg", "rb");
$file = fread($fp, 4096);
fclose($fp);
if($fp)
{
	echo "FILE";
}
else
{
	echo "NO FILE";
}

echo $file;
?>

    I have resolved this issue.

    Seems the reason fopen was accepting a 404 as valid was beacuse fopen was using The cURL wrapper instead of the http.

    I recompiled php to a newer version without curlwrappers enabled and now fopen functions as expected, with the http wrapper.

    Thanks,

      How were you able to determine it was using curl wrappers?

        I added this line of code after calling fopen

        echo var_dump(stream_get_meta_data($fp));

        This gave me all the information of what the handle was doing.

        http://pvt-test.tooshocking.com/fopentest.php

        the wrapper type before said:

        ["wrapper_type"]=>
        string(4) "cURL"

        I recompiled PHP without the curlwrapper option enabled and now it says

        ["wrapper_type"]=>
        string(4) "http"

        and it works as it should now.

          Write a Reply...