In my app, I am checking for cURL.

if (!dl('php_curl.dll') && !dl('curl.so')) {
     // cURL not installed :-(
} else {
    // cURL installed! YAY!
}

This loads the curl lib for *nix and windows. if both fail, curl support isn't installed. However, on multithreaded servers, this would give:

PHP Warning: dl(): Not supported in
multithreaded Web servers - use
extension=php_curl.dll

Fine. Then how do I check if curl is installed and /or active?

I found $_ENV["NUMBER_OF_PROCESSORS"] is "2" on his machine. Is multiprocessor the same as multithread?

How can the app test if he has uncommented extension=php_curl.dll in his php.in?

    dl is not really the greatest way to check for curl being installed since that will actually try to load the extension if it hasnt been already.

    try using

    if (function_exists('curl_init')) {
      //curl is installed and loaded
    } else {
      //curl isnt installed
    }
    

      Thanks Drew. I should have said that I need to have curl loaded anyway, so I was loading and checking it's results. I'll use this in a pre-installation check script. Very useful, thanks.

      If the function doesn't exist, that means curl doesn't exist, right? If curl is installed, how do I check if it's been loaded or not? If it's not, I'll need to load it. If it's NOT a multithreaded server, I'll use dl(), otherwise I'll have it

      die("make sure extension=php_curl.dll is uncommented in the php.ini");

      So I'm 75% the way there. I need to figure out how to determine if the machine is a multithreaded server...

        Right if the function doesnt exist, it means for linux, php wasnt compiled --with-curl and for windows extension=php_curl.dll is commented out.
        I think a function that will be very useful to use is [man]extension_loaded[/man]

        if (!extension_loaded('curl')) {
          //curl is not loaded
        } else {
          //curl is loaded
        }
        

          As of PHP 4.3.0 there is absolutely no need to use curl any more.

          Just use file streams with http(s) files instead. If you need to do a POST or supply more parameters, create a stream context before you use fopen() and set the parameters on the stream context.

          Mark

            Thank you Drew and Mark.

            I'm getting conflicting message from the manual about stream contexts. fopen mentions it's available only in php5, where as the Reference CXXIX, Stream Functions, seem to say some functions are available in 4, and additional ones in 5.

            😕

              9 days later

              I'm using it in several applications, and I can categorically state that they work fine in PHP 4.3.x (not before though, I imagine)

              Look at the docs - you can do HTTP POSTs and everything, just using the PHP stream context functions and fopen()

              Mark

                Write a Reply...