Here is a brief description of two:
One, increase time limit of timeout
Note here: Set_time_limit only sets the timeout for your PHP program, not the timeout for the file_get_contents function to read the URL.
I initially thought Set_time_limit could also affect File_get_contents, which was later tested to be ineffective. The real modification of the file_get_contents delay can be resource $context timeout parameters:
Copy Code code as follows:
$opts = Array (
' HTTP ' =>array (
' Method ' => ' get ',
' Timeout ' =>60,
)
);
$context = Stream_context_create ($opts);
$html =file_get_contents (' http://www.example.com ', false, $context);
Fpassthru ($FP);
If 二、一次 has a delay, try it a few more times.
Sometimes failure is due to the network and other factors, there is no solution, but can modify the program, failed to retry several times, still fail to give up, because file_get_contents () if the failure will return FALSE, so you can write the following code:
Copy Code code as follows:
$cnt = 0;
while ($cnt < 3 && ($str = @file_get_contents (' http ... ')) ===false $cnt + +;