So let me get this straight about CURL

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

    So let me get this straight about CURL

    1. In order to make an http (or https) request with PHP, I need to
    recompile php with cURL.

    2. In order to install CURL I have to upgrade my openssl rpm, even
    though I'm runing a version of linux that's only like 3 months old
    (fedora c2 stable), because curl needs libcrypto.so.4.

    3. In order to install libcrypto.so.4 I have to upgrade my openssl
    (took me forever to figure that out).

    4. Upgrading my openssl rpm pretty much requires re-installing just
    about everything in my entire linux distro that's useful, because half
    of everything uses libcrypto.

    Ergo:

    To make php make an https request, you either have to do the entire
    https request yourself starting with an tcp connection, or you can use
    curl which means (for nearly everyone), re-installing half the
    software on your server. http://tinyurl.com/6ph53

    And with perl all you do is download one module from cpan. Oh no,
    wait, it already comes with the perl distro.

    Anyone correct me or do I have that all right?
  • Pieter Nobes

    #2
    Re: So let me get this straight about CURL

    mrbog wrote:
    [color=blue]
    > 1. In order to make an http (or https) request with PHP, I need to
    > recompile php with cURL.
    >
    > 2. In order to install CURL I have to upgrade my openssl rpm, even
    > though I'm runing a version of linux that's only like 3 months old
    > (fedora c2 stable), because curl needs libcrypto.so.4.
    >
    > 3. In order to install libcrypto.so.4 I have to upgrade my openssl
    > (took me forever to figure that out).
    >
    > 4. Upgrading my openssl rpm pretty much requires re-installing just
    > about everything in my entire linux distro that's useful, because half
    > of everything uses libcrypto.
    >
    > Ergo:
    >
    > To make php make an https request, you either have to do the entire
    > https request yourself starting with an tcp connection, or you can use
    > curl which means (for nearly everyone), re-installing half the
    > software on your server. http://tinyurl.com/6ph53
    >
    > And with perl all you do is download one module from cpan. Oh no,
    > wait, it already comes with the perl distro.
    >
    > Anyone correct me or do I have that all right?[/color]
    You can't expect that the CD's of Fedora upgrade themselves. I always
    use minicd's (like ArchLinux Base or FreeBSD miniinst) so only the base
    system is installed. Then I let it install the rest via a package
    manager (pacman or ports), so I don't have to search for rpm's (pacman
    -Sy php or cd /usr/ports/www/mod_php && make install clean does the
    trick). With the FreeBSD ports you even get a nice screen asking you
    which extentions for PHP you want to have installed and it will
    automatically install them and their dependencies.

    --
    Pieter Nobels

    Comment

    • Colin McKinnon

      #3
      Re: So let me get this straight about CURL

      mrbog wrote:
      [color=blue]
      > 1. In order to make an http (or https) request with PHP, I need to
      > recompile php with cURL.
      >[/color]

      No; I use file(..) for GET and my own protocol implementation for POST via
      HTTP. It's possible to route these through stunnel if you need SSL but
      don't want to do the curl thing.
      [color=blue]
      > 2. In order to install CURL I have to upgrade my openssl rpm, even
      > though I'm runing a version of linux that's only like 3 months old
      > (fedora c2 stable), because curl needs libcrypto.so.4.
      >[/color]

      Given it's nature, keeping SSL up to date is pretty much a 'must'.
      [color=blue]
      > 4. Upgrading my openssl rpm pretty much requires re-installing just
      > about everything in my entire linux distro that's useful, because half
      > of everything uses libcrypto.
      >[/color]

      You don't *have* to upgrade it just install the alternative version
      alongside, or use an older version of libcurl. Note that this would be
      rather a dumb thing to do.

      Can't comment on how to do it with Perl but I suspect it might amount to the
      silly suggestions in the previous paragraph.

      HTH

      C.

      Comment

      • Daniel Stenberg

        #4
        Re: So let me get this straight about CURL

        dterrors@hotmai l.com (mrbog) wrote:
        [color=blue]
        > 1. In order to make an http (or https) request with PHP, I need to
        > recompile php with cURL.[/color]

        I believe this is correct, unless you can find a pre-packaged PHP that
        already has PHP/CURL[*] support built-in. Such packages exist for
        several Linux distributions at least.
        [color=blue]
        > 2. In order to install CURL I have to upgrade my openssl rpm[/color]

        Hold it. If you can build PHP from source, why can't you build curl
        from source too? If you do, you won't get any curl package that
        depends on a OpenSSL version you don't have.
        [color=blue]
        > though I'm runing a version of linux that's only like 3 months old
        > (fedora c2 stable), because curl needs libcrypto.so.4.[/color]

        Not entirely true. libcurl (which is the library PHP/CURL uses) is
        built to use OpenSSL. If someone packaged a libcurl to require
        libcrypto.so.4 then so be it, that packaged libcurl requires it. That
        doesn't mean that libcurl itself requires that particular libcrypto
        version.
        [*] = note that the project curl provides curl the command line tool
        and the libcurl library. The curl PHP offers is better called PHP/CURL
        or mod_curl to more clearly differentiate it from the other curls.

        Comment

        • Nikolai Chuvakhin

          #5
          Re: So let me get this straight about CURL

          dterrors@hotmai l.com (mrbog) wrote in message
          news:<cbd4bb52. 0408251728.6d4f 3f73@posting.go ogle.com>...[color=blue]
          >
          > In order to make an http (or https) request with PHP, I need to
          > recompile php with cURL.[/color]

          No you don't. Consider this simple function:

          function HTTP_GET($host= 'localhost', $path='/', $port=80, $timeout=10) {

          // This function takes up to four optional arguments:
          //
          // $host (defaults to 'localhost') -- the name of target HTTP host,
          // $path (defaults to '/') -- the target path
          // $port (defaults to 80) -- the target port number
          // $timeout (defaults to 10) -- maximum allowed waiting time
          //
          // On success, the function returns an associative array of two
          // string fields: 'headers' (HTTP headers returned by the target
          // host) and 'content' (the body of the HTTP response). On failure,
          // the function returns FALSE.

          $headers = '';
          $content = '';
          $flag = false;
          $fp = fsockopen($host , $port, $errno, $errstr, $timeout);
          if (!$fp) {
          echo "Error $errno: $errstring. \r\n";
          return false;
          } else {
          fwrite($fp, "GET $path HTTP/1.0\r\n" .
          "Host: $host\r\n\r\n") ;
          while (!feof($fp)) {
          $line = fgets($fp, 10240);
          if ($flag) {
          $content .= $line;
          } else {
          $headers .= $line;
          if (strlen(trim($l ine)) == 0) {
          $flag = true;
          }
          }
          }
          fclose($fp);
          return array('headers' => $headers, 'content' => $content);
          }
          }

          Example of usage:

          $host = 'www.yourhost.c om'; // Assume we want to retrieve a file
          $path = '/path/to/file.htm'; // http://www.yourhost.ru/path/to/file.htm
          if ($response = HTTP_GET($host, $path)) {
          extract($respon se);
          }

          POST requests are not much more difficult...

          Cheers,
          NC

          Comment

          • Chung Leong

            #6
            Re: So let me get this straight about CURL

            "mrbog" <dterrors@hotma il.com> wrote in message
            news:cbd4bb52.0 408251728.6d4f3 f73@posting.goo gle.com...[color=blue]
            > Ergo:
            >
            > To make php make an https request, you either have to do the entire
            > https request yourself starting with an tcp connection, or you can use
            > curl which means (for nearly everyone), re-installing half the
            > software on your server. http://tinyurl.com/6ph53
            >
            > And with perl all you do is download one module from cpan. Oh no,
            > wait, it already comes with the perl distro.
            >
            > Anyone correct me or do I have that all right?[/color]

            Well, on Windows you just unzip the binary distribution into C:\PHP and
            everything works more or less.

            If you are going to use Linux, then don't complain about having to compile
            stuff.


            Comment

            • Chris Hope

              #7
              Re: So let me get this straight about CURL

              Nikolai Chuvakhin wrote:
              [color=blue]
              > dterrors@hotmai l.com (mrbog) wrote in message
              > news:<cbd4bb52. 0408251728.6d4f 3f73@posting.go ogle.com>...[color=green]
              >>
              >> In order to make an http (or https) request with PHP, I need to
              >> recompile php with cURL.[/color]
              >
              > No you don't. Consider this simple function:[/color]

              [snip]

              The fopen(), include(), file(), file_get_conten ts() etc functions support
              http urls as the filename, so you don't need to open a socket connection.
              You can do it like this:

              $webpage = file_get_conten ts('http://www.domain.com/foo.html');

              (Note that you need PHP 4.3.0 or higher for file_get_conten ts(). Use fopen()
              etc for earlier versions).

              This works for http requests but you still need the ssl libraries installed
              to make an https request.

              Check out the following for more info

              and note in particular "you can use HTTP and FTP URLs with most of the
              functions that take a filename as a parameter."

              --
              Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

              Comment

              • Nikolai Chuvakhin

                #8
                Re: So let me get this straight about CURL

                Chris Hope <blackhole@elec trictoolbox.com > wrote
                in message news:<109358108 1_3227@216.128. 74.129>...[color=blue]
                >
                > The fopen(), include(), file(), file_get_conten ts() etc functions support
                > http urls as the filename, so you don't need to open a socket connection.[/color]

                Generally speaking, you are right. But, as we all know, the devil
                is in details. In particular, one can encounter one or both of the
                following errors when trying to access remote files via file system
                functions:

                Warning: file([URL]) - Success in file.php on line XXX
                Warning: fopen([URL], "r") - Undefined error: 0

                It's been known to happen even when working with Amazon Web Services
                and Google.

                In addition, file system functions do not allow you to capture HTTP
                headers returned by the remote server, and those may be important,
                especially if you are trying to implement data retrieval from a
                remote site with a cookie-based authentication system.

                Cheers,
                NC

                Comment

                • mrbog

                  #9
                  Re: So let me get this straight about CURL

                  "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message news:<qMGdnWiNp bXXOLPcRVn-iA@comcast.com> ...[color=blue]
                  >
                  > Well, on Windows you just unzip the binary distribution into C:\PHP and
                  > everything works more or less.
                  >
                  > If you are going to use Linux, then don't complain about having to compile
                  > stuff.[/color]


                  When I use perl and linux, I don't have to recompile openssl. You
                  still sure I shouldn't complain?

                  Or maybe PHP is a mainly-microsoft thing, eh? wink wink.

                  Comment

                  Working...