Doubts about php file_get_content timeout setting

one of my programs will initiate a http request to another project, using the file_get_content function. I need to make sure that the request is made, but I don"t need to return a result. Can I set the file_get_content timeout to 1 second? Because of the 3 seconds currently set, many slow requests

Mar.28,2021

file_get_contents () is specially used to obtain the file data stream. Either get it or report an error. If you just want to request, try curl . You can set the request duration


.

two ways

1. Temporarily modify ini configuration directly

ini_set('default_socket_timeout', 900);//

2. This function also has other parameters

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

echo file_get_contents('http://example.com/', false, $ctx);
Menu