Politik

Hey guys,

I'm a newbie to

PHP

  and I am building a basic scraper script. Is there a big difference between using File_get_Contents and cURL? Is one more beneficial than the other?

perkiset

Absolutely

apple

 s and oranges.

cURL is a lower-leve tool that allows you to customize your interaction with a webserver pretty precisely. The only way really to go deeper is to write your own downloader with fundamental functions like fsocket. cURL wraps a bunch of commonly accessed things like headers, cookies etc into tidy functions that allows you to access stuff that would be more difficult to get by other means.

file_get_contents is a one-function-does-all sort of grab - it brings in the entire page and returns it to you as ablob... and that's it. Many ISPs have the http:// method for file_get_contents shut down - which is probably a simple and silly way to hold back novice programmers.

The answer you're looking for:
You should start with fle_get_contents (provided it works @ your isp) because it sill simplify the "getting of the page" portion of your scraper for today. It will allow you to focus on things like

regex

 s, loops and such to become a stronger programmer. Shortly, however, you'll be very limited by it and want to look at cURL - but by then, you'll be a little bit stronger and you'll understand the tool.

Applause
/p

georgiecasey

Yeah, start with file_get_contents and then you'll eventually need the power of cURL. But cURL also has it's limitations like seeing exactly what header it sent to the server which is not possible in current version of

php

  so I recently started using fsocksopen and been using it since. You also get to

learn

  exactly how HTTP works.

perkiset

Georgie -

That's exactly what I do... I don't use cURL at all, but it's a great tool.

My WebRequest class is in the code repository if you want to look at it... it's pretty full featured and gives you complete access to everything. Use the Search and look for WebRequest.

/p

Politik

Sounds good, thanks guys!!


Perkiset's Place Home   Politics @ Perkiset's