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
test.php
use thesession_start()
test.php
launch aPOST request
on thepage.php
page.php
use thesession_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
How to Read Last Lines (I.E. "Tail") from a File Using PHP
What's the Difference Between ++$I and $I++ in PHP
Pdo Prepared Statements With Wildcards
How to Get Rid of Eval-Base64_Decode Like PHP Virus Files
Restructure Multidimensional Array of Column Data into Multidimensional Array of Row Data
Calculate Age Based on Date of Birth
Match A^N B^N C^N (E.G. "Aaabbbccc") Using Regular Expressions (Pcre)
Retrieving Multiple Result Sets With Stored Procedure in PHP/MySQLi
How to Retrieve Request Payload
How to Get Last Key in an Array
Variable-Length Lookbehind-Assertion Alternatives For Regular Expressions
Fatal Error: Call to a Member Function Prepare() on Null
Laravel Update Model With Unique Validation Rule For Attribute
Round Up to Nearest Multiple of Five in PHP
Best Practice Multi Language Website
Storing and Displaying Unicode String (हिन्दी) Using PHP and MySQL