This article describes the PHP file_get_contents advanced usage, share to everyone for your reference.
The specific analysis is as follows: first solve the file_get_contents timeout problem
After the time-out error, like JS in the settimeout like a try, the error more than 3 or 5 times after the confirmation that the server can not be connected and completely abandoned.
Here's a quick introduction to two workarounds:
One, increase the time limit of timeout note:
Set_time_limit only sets the time-out for your PHP program, not the time-out for the file_get_contents function to read the URL.
At first I thought set_time_limit could also affect File_get_contents, which was later tested to be ineffective.
The real modification file_get_contents delay can be used with the timeout parameter of the resource $context.
The PHP program code is as follows:
<>< p=""><>
Fpassthru ($FP);
Second, several attempts
The PHP program code is as follows:
$cnt = 0;
while ($cnt < 3 && ($str = @file_get_contents (' http ... ')) {===false) {
$cnt + +;
}
The above method against timeout is OK.
Third, using file_get_contents to achieve post
as follows: PHP program code
echo Post (' http://www.scutephp.com ', $data);
Note the set_time_out of the document header or the entire document is timed out.