PHP uses file_get_contents instead of using Curl instance _php techniques

Source: Internet
Author: User
Tags curl

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.