By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,304 Members | 3,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,304 IT Pros & Developers. It's quick & easy.

when does it ever make sense to use curl?

P: n/a

I'm reading over this page:

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

What I'm missing is why? What problem does curl solve? What does it
make easier? When would I use its functions, instead of simpler
functions like file() or fsocketopen()?

May 18 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
lawrence k wrote:
I'm reading over this page:

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

What I'm missing is why? What problem does curl solve? What does it
make easier? When would I use its functions, instead of simpler
functions like file() or fsocketopen()?


Ever tried to post info to another page strictly through PHP?

Curl takes care of some of the overhead. Obviously you can do anything in PHP
that you can in Curl. Curl just makes things easier.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 18 '06 #2

P: n/a
lawrence k wrote:
I'm reading over this page:

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

What I'm missing is why? What problem does curl solve? What does it
make easier? When would I use its functions, instead of simpler
functions like file() or fsocketopen()?


I am pretty sure that you can't connect to a web server through a proxy
using a file stream. CURL also offers better backward compatibility.
You can't, for instance, do a HTTP POST using a stream context until
4.3.4 (IIRC).

May 18 '06 #3

P: n/a
On Wed, 17 May 2006 20:46:16 -0700, lawrence k wrote:
I'm reading over this page:

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

What I'm missing is why? What problem does curl solve? What does it make
easier? When would I use its functions, instead of simpler functions like
file() or fsocketopen()?


Curl automatically handles session cookies if you're retrieving multiple
pages for a different site.

Curl is a known web page connection interface, using the file() interface
with allow_url_fopen (to enable fopen to open web pages) can lead to
security holes (particularly with some dodgy register_globals code).

Cheers,
Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

May 18 '06 #4

P: n/a
Carved in mystic runes upon the very living rock, the last words of Andy
Jeffries of comp.lang.php make plain:
On Wed, 17 May 2006 20:46:16 -0700, lawrence k wrote:
I'm reading over this page:

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

What I'm missing is why? What problem does curl solve? What does it
make easier? When would I use its functions, instead of simpler
functions like file() or fsocketopen()?


Curl automatically handles session cookies if you're retrieving
multiple pages for a different site.

Curl is a known web page connection interface, using the file()
interface with allow_url_fopen (to enable fopen to open web pages) can
lead to security holes (particularly with some dodgy register_globals
code).


I have a couple of homebrew functions I use for simple POSTs and GETs,
using fsockopen() but, as others have pointed out, there are things that
CURL simplifies, like negotiating an SSL connection. I want to do it in
straight PHP one of these days, just for the hell of it, but for now I
use CURL.

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
May 18 '06 #5

P: n/a
NC
lawrence k wrote:

I'm reading over this page:

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

What I'm missing is why?
And why not? cURL was not developed for PHP, but why not use it if
it's available?
What problem does curl solve? What does it make easier?
When would I use its functions, instead of simpler functions
like file() or fsocketopen()?


Using fsockopen() is not that simple compared to cURL; you have to keep
track of redirects, cookies, etc., and remember to separate HTTP
headers from the data proper. As to file()/readfile(), PHP sometimes
experiences problems opening dynamically generated remote files via
file system functions, even with allow_url_fopen = On. Sometimes it
even generates error messages like these:

Warning: file([url]) - Success in file.php on line X
Warning: fopen([url], 'r') - Undefined error: 0

Cheers,
NC

May 18 '06 #6

P: n/a

Jerry Stuckle wrote:
lawrence k wrote:
I'm reading over this page:

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

What I'm missing is why? What problem does curl solve? What does it
make easier? When would I use its functions, instead of simpler
functions like file() or fsocketopen()?


Ever tried to post info to another page strictly through PHP?

Curl takes care of some of the overhead. Obviously you can do anything in PHP
that you can in Curl. Curl just makes things easier.


Yes. I used fsocketopen. I think it took less than 20 lines of code, so
how much simpler could Curl make it?

May 19 '06 #7

P: n/a
On Thu, 18 May 2006 19:06:35 -0700, lawrence k wrote:
Ever tried to post info to another page strictly through PHP?

Curl takes care of some of the overhead. Obviously you can do anything
in PHP that you can in Curl. Curl just makes things easier.


Yes. I used fsocketopen. I think it took less than 20 lines of code, so
how much simpler could Curl make it?


$ch = curl_init("http://www.domain.cxm/foo.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_exec($ch);
curl_close($ch);

So, 25% of the LOC.

Plus you automatically get session cookie handling. How many extra lines
of code would that be? Oh, by the way, we've moved this page to an HTTPS
host now, how many extra lines of code would that be?

Don't get me wrong, there are a large number of times when I've happily
re-invented the wheel if I have a really specific idea of the way
something should work (even if there's a PEAR class to do it), but I make
it a rule to look at it first before making a conscious decision to
duplicate effort.

In this case, there's no way I'd overlook a PHP built in and rewrite it
myself using sockets.

Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

May 22 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.