file_get_contents ($ url) Error returned

0

Hello, I found a function here in the stack for a problem similar to mine however I'm having a problem.

The function is:

function file_get_contents_retry($url, $attemptsRemaining=3) {
    $content = file_get_contents($url);
    $attemptsRemaining--;

    if( empty($content) && $attemptsRemaining > 0 ) {
        return file_get_contents_retry($url, $attemptsRemaining);
    }

    return $content;
}

My problem is that after getting the information I have a echo "sucesso"; that returns a $ .post function.

However, it seems to me that when the function of some error in some attempt, $ .post, besides catching the success of the echo it takes this error.

I need to know how to remove this error.

Any tips?

    
asked by anonymous 05.10.2017 / 15:36

1 answer

0

Replace the first line of the function with:

$content=@file_get_contents($url);

It looks like this:

function file_get_contents_retry($url, $attemptsRemaining=3) {
    $content = @file_get_contents($url);
    $attemptsRemaining--;

    if( empty($content) && $attemptsRemaining > 0 ) {
        return file_get_contents_retry($url, $attemptsRemaining);
    }

    return $content;
}
    
05.10.2017 / 16:36