PHP Curl VS File_Get_Contents

PHP cURL vs file_get_contents

file_get_contents() is a simple screwdriver. Great for simple GET requests where the header, HTTP request method, timeout, cookiejar, redirects, and other important things do not matter.

fopen() with a stream context or cURL with setopt are powerdrills with every bit and option you can think of.

curl v/s file_get_contents performance for a file on same server

With CURL you can expect worse performance.

Why?

Because it initiates a HTTP request, going through the network, invoking a response on the HTTP-server, starting some process (eg PHP), fetching the file, and then back to CURL.

If you use file_get_contents() you are only fetching the file, in the same process. It is bound to be faster than CURL.

curl or file_get_contents not working

THE REAL PROBLEM

  1. test.php use the session_start()
  2. test.php launch a POST request on the page.php
  3. page.php use the session_start() <<< freeze

We can't use 2 sessions PHP at same time. The session is locking and create infinite loop.

Thank you guys for helping me find the solution.

Why do small spaces keep showing up in my web pages?

The whitespace (carriage return included) is usually rendered as space in all browsers.

You need to put the elements one after another, but you can use a trick:

<a href="page1.html"><img src="image1.png" 
/></a><a href="page2.html"><img src="image2.png"
/></a><a href="page3.html"><img src="image3.png"
/></a>

This also looks a little ugly, but it's still better than one single line. You might change the formatting, but the idea is to add carriage returns inside the elements and not between them.

file_get_contents vs cUrl. Which is more relevant and secure?

I think curl is more secure because if you're working with remote file with file_get_contents() you need to enable ‘allow_url_fopen’

reference :

http://25labs.com/alternative-for-file_get_contents-using-curl/

http://phpsec.org/projects/phpsecinfo/tests/allow_url_fopen.html

And continuing discussion from the comments in the question, yes cURL give you more option and if you want to check more you can see it in the documentation here

For file_get_contents() it just a simple GET request.



Related Topics



Leave a reply



Submit