when does it ever make sense to use curl?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawrence k

    when does it ever make sense to use curl?


    I'm reading over this page:



    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()?

  • Jerry Stuckle

    #2
    Re: when does it ever make sense to use curl?

    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
    =============== ===

    Comment

    • Chung Leong

      #3
      Re: when does it ever make sense to use curl?

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

      Comment

      • Andy Jeffries

        #4
        Re: when does it ever make sense to use curl?

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

        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

        Comment

        • Alan Little

          #5
          Re: when does it ever make sense to use curl?

          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.

          --
          Alan Little
          Phorm PHP Form Processor

          Comment

          • NC

            #6
            Re: when does it ever make sense to use curl?

            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?[/color]

            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

            Cheers,
            NC

            Comment

            • lawrence k

              #7
              Re: when does it ever make sense to use curl?


              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?

              Comment

              • Andy Jeffries

                #8
                Re: when does it ever make sense to use curl?

                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]

                $ch = curl_init("http ://www.domain.cxm/foo.php");
                curl_setopt($ch , CURLOPT_POST, 1);
                curl_setopt($ch , CURLOPT_POSTFIE LDS, $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

                Comment

                Working...