The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 17, 2019, 05:39:47 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Difference between File_Get_contents & Curl  (Read 2667 times)
Politik
Rookie
**
Offline Offline

Posts: 11


View Profile
« on: August 24, 2007, 12:46:20 PM »

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?
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: August 25, 2007, 11:18:09 AM »

Absolutely apples 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 regexs, 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.


/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
georgiecasey
Rookie
**
Offline Offline

Posts: 16


View Profile
« Reply #2 on: August 26, 2007, 08:32:43 PM »

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.
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: August 26, 2007, 09:42:04 PM »

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
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Politik
Rookie
**
Offline Offline

Posts: 11


View Profile
« Reply #4 on: August 27, 2007, 01:26:24 PM »

Sounds good, thanks guys!!
Logged

No links in signatures please
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!