Reputation: 11
What may be the reason for this simple code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://somepage.com/path');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERIFYPEER, false);
$output = curl_exec($ch);
be consistently 1+ seconds slower than Firefox is?
I have tested the PHP code using
$timestart = microtime(true);
echo microtime(true) - $timestart;
and Firebug (Net tab) on Firefox.
https://somepage.com/path returns plain JSON, it takes around 500ms on Firefox and 1500 with cURL in PHP.
Upvotes: 1
Views: 916
Reputation: 39405
Accept-Encoding gzip, deflate
Firefox always asks for compressed content to the remote site(if available). I guess in your case, the site is returned the compressed html through the browser. But while fetching the html using curl, you didn't set anything like that in your code.
Try to add this on your curl code and check the performance again.
curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
If no change found, then try below one.
curl_setopt($ch, CURLOPT_ENCODING, ""); // supports all
Upvotes: 1