This article is an example of PHP using file_get_contents instead of using curl method, share for everyone to reference. The implementation methods are as follows:
File_get_contents instead of using curl is rare, but sometimes you run into the server does not support curl we can use file_get_contents instead of using curl, see below for example.
When everything is done to discover that the server is really unable to use curl. Or if Curl does not support HTTPS. Curl HTTPS occurs when 502. You do not want to reload the site environment, you switch to file_get_contents instead of it.
Curl frequently used curl get curl post
Curl get substitution directly with file_get_contents ($url) on it
The Curl Post replaces the following:
Copy Code code as follows:
function Post ($url, $post = null) {
$content = Http_build_query ($post);
$content _length = strlen ($content);
$options = Array (
' http ' => array (
' Method ' => ' POST ',
' Header ' => ' content-type:application/x-www-form-urlencoded ',
' Content ' => $post
)
);
Return file_get_contents ($url, False, Stream_context_create ($options));
}
I hope this article will help you with your PHP program design.