php uses file_get_contents instead of using the curl instance

  • 2021-07-26 07:15:12
  • OfStack

In this paper, the method of using file_get_contents instead of curl is described as an example, which is shared for your reference. The specific implementation method is as follows:

It is rare to use file_get_contents instead of curl, but sometimes when you encounter a server that does not support curl, we can use file_get_contents instead of curl. Let's take a look at an example below.

When it is found that the server really cannot use curl after exhausting 1-cut methods. Or when curl does not support https. curl https appears at 502. If you don't want to reinstall your site environment, use file_get_contents instead.
curl Frequently Used curl get curl post
Instead of curl get, simply use file_get_contents ($url)
curl post replaces 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 is helpful to everyone's php programming.


Related articles: