This is an old topic, but in my last test on one of my APIs, cURL is faster and more stable. Sometimes file_get_contents for a larger request takes more than 5 seconds, when cURL only needs from 1.4 to 1.9 seconds, which is twice as fast.
I need to add one note to just send a GET and receive JSON content. If you configured cURL correctly, you will have a great answer. Just βtellβ cURL what you need to send, and what you need to receive and what it is.
For your example, I would like to make this setting:
$ch = curl_init('http://api.bitly.com/v3/shorten?login=user&apiKey=key&longUrl=url'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); $result = curl_exec($ch);
This query will return data with a maximum value of 0.01 seconds.
Ivijan Stefan StipiΔ May 16 '16 at 14:12 2016-05-16 14:12
source share