I'm doing a script
to get content from a url and I found here , here and aqui what can be done with curl
and with file_gets_contents()
, but I'm not entirely clear about two things:
- What are the differences between the two?
- Which is the most appropriate to get
html
from a url to then analyze thehtml
?
The code I used is this:
file_get_contents
$html = file_get_contents($urlFlujo, false, $context);
curl
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);
curl_close($ch);
They perform the same function as obtaining an html from an url, but I am not clear that they work in the same way or serve exactly the same.
I ask only empirical and demonstrable data of which form is the most appropriate (shorter execution time, less consumption of resources, etc.) for my case.