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()?
lawrence k wrote:[color=blue]
> 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()?
>[/color]
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. jstucklex@attgl obal.net
=============== ===
lawrence k wrote:[color=blue]
> 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()?[/color]
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).
On Wed, 17 May 2006 20:46:16 -0700, lawrence k wrote:[color=blue]
> 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()?[/color]
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_global s code).
Carved in mystic runes upon the very living rock, the last words of Andy
Jeffries of comp.lang.php make plain:
[color=blue]
> On Wed, 17 May 2006 20:46:16 -0700, lawrence k wrote:[color=green]
>> 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()?[/color]
>
> 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_global s
> code).[/color]
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.
And why not? cURL was not developed for PHP, but why not use it if
it's available?
[color=blue]
> What problem does curl solve? What does it make easier?
> When would I use its functions, instead of simpler functions
> like file() or fsocketopen()?[/color]
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
Jerry Stuckle wrote:[color=blue]
> lawrence k wrote:[color=green]
> > 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()?
> >[/color]
>
> 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.[/color]
Yes. I used fsocketopen. I think it took less than 20 lines of code, so
how much simpler could Curl make it?
On Thu, 18 May 2006 19:06:35 -0700, lawrence k wrote:[color=blue][color=green]
>> 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.[/color]
>
> Yes. I used fsocketopen. I think it took less than 20 lines of code, so
> how much simpler could Curl make it?[/color]
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.
Comment