How to get rid of the "Uncaught TypeError: feof(): supplied resource is not a valid stream resource" logged error?

276 Views Asked by At

For years now, I've been trying to solve this insanely annoying issue. Seemingly at random, my fsockopen-using code fails and PHP-logs the error:

PHP Fatal error: Uncaught TypeError: feof(): supplied resource is not a valid stream resource

For the if (feof($the_connection)) line.

Normally, it works. This only happens "sometimes", presumably when there's a temporary network issue or a proxy is temporarily unavailable or something like that.

I've tried to use @ to suppress it. Doesn't work. I've tried looking in the manual for feof to see if it has some parameter to turn this off. It doesn't.

In desperation, I've even tried wrapping it inside a try...catch block to make it shut up. It doesn't help:

try
{
    if (feof($the_connection))
        return false;
}
catch (exception $e)
{
    return false;
}

No matter what I do, the damn "TypeError" sometimes happens and is logged, frustrating me since my code isn't "rock solid" to handle this case.

Online, there's no reference at all to this error, which is very unusual.

How do I make it stop? What can I possibly need to do since I actually do "try" and "catch"?

0

There are 0 best solutions below