Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

explain logic behind the curl process in php

Tags:

php

curl

I am using the PHP and parsing url content from web and I know two method are there for that file_get_contents(url) and curl. I know we have more option with curl so i am using that But i just wanted to know the process behind the curl. How it works when we make a curl request from scrach in brief

like image 723
vishalg Avatar asked Feb 20 '23 06:02

vishalg


1 Answers

The PHP cURL package just exposes the cURL/libcurl API (which are written in C) in PHP. cURL is really useful for moving data across all sorts of protocols, and has a lot of nice options. On the other hand, file_get_contents is one of the base PHP file operations, and it relies on the kernel to try to find the resource requested. In general, cURL will be a better choice, though often it takes a few more lines of code. One issue with file_get_contents() is that in some cases the connection is left open after the request is made, so the function call will block the script until the request times out and you may see a lot of lag.

References:

http://php.net/manual/en/book.curl.php

http://en.wikipedia.org/wiki/CURL

http://www.php.net/manual/en/ref.filesystem.php

like image 160
Sam Grondahl Avatar answered Feb 27 '23 21:02

Sam Grondahl