PHP - failed to open stream: Connection timed out

0

In the code below, via localhost xampp works correctly by accessing a server in ipfixo or ddns, but the same code in the hosting returns me:

  

"failed to open stream: Connection timed out"

$url  = sprintf("%s%s%s/%s", $servidor, $AutenticarUsuario, $usuario, $senha);

$ctx = stream_context_create(array('http'=>
                    array(
                            'timeout' => 10,  //10 segundos
                    )
            ));         

$rest = file_get_contents($url, false, $ctx);
    
asked by anonymous 16.05.2017 / 22:12

1 answer

0

It is probably some server security policy that is blocking the connection to the remote server, since file_get_contents virtually "catches" all the contents of the remote file and inserts it in your code, which can mean a security breach, so many hosting servers prevent this function from bringing content external to the site.

Consider doing the query using curl instead and file_get_contents ().

Here's a tutorial (unfortunately it's in English, but the code is readable ... rs)

link

Some sources to understand the operation of file_get_contents:

link

link

    
16.05.2017 / 22:28