Alternative to cURL for my update checker?

Discussion in 'PHP' started by Chuckun, Jun 7, 2012.

  1. #1
    Hey guys,

    I made a license + update checker for my premium scripts (using cURL) and until now it's worked fine, but more and more people are purchasing who reportedly do not have cURL enabled on their server.

    Can anyone recommend an alternative for if the curl pre-check returns false?

    Obviously anything revolving around allow_url_fopen is pointless because that's more commonly disabled than cURL is..

    Thanks a lot in advance guys,

    Chuck
     
    Chuckun, Jun 7, 2012 IP
  2. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #2
    Are you SURE they don't have cURL enabled? Or actually...are THEY sure? Most webhosts will have cURL enabled since it's a very common lib.

    - You could use file_get_contents() to fetch a file...BUT then again some web hosts may have remote file gets blocked in php...

    - You could fire off the "wget" with the exec() function...BUT again that could pose a security risk.

    - You could use SOCKETs.. This is an example from the PHP web site... ofcourse you must alter to your liking...BUT it takes a lot of code to do something simple.

    
    $fp = fsockopen("www.yourdomain.com", 80, $errno, $errstr, 30);
    
    if (!$fp)
    {
        print "Couldn't connect: $errstr ($errno)\n";
    } else
    {
        $out = "GET /some_file_to_fetch HTTP/1.1\r\n";
        $out .= "Host: www.yourdomain.com\r\n";
        $out .= "Connection: Close\r\n\r\n";
    
        fwrite($fp, $out);
    
        while (!feof($fp)) {
            print fgets($fp, 128); // or append to variable to access later
        }
    
        fclose($fp);
    }
    
    PHP:

    - You could rewrite in Perl and use LWP::UserAgent... LWP comes shipped with Perl and every server runs Perl...BUT then your users would need to know how to install a Perl script (just upload ascii and chmod 0755) and change the shebang to the proper path to perl binary.


    Before you do anything else...make sure your users know for a fact cURL isn't installed. They may just be assuming it isn't.
     
    Last edited: Jun 8, 2012
    NetStar, Jun 8, 2012 IP
    Chuckun likes this.
  3. Chuckun

    Chuckun Well-Known Member

    Messages:
    1,161
    Likes Received:
    60
    Best Answers:
    2
    Trophy Points:
    150
    #3
    When I say they reportedly dont have CURL installed, thats based on my pre-checks :p

    function curl_check() {
    	if (in_array('curl', get_loaded_extensions())) {
    		return true;
    	} else {
    		return false;
    	}
    }
    PHP:
    If that returns true, I run the update checker.. If it returns false, I iframe a URL which when run, stores some information, including the fact that CURL wasn't used :p

    file_get_contents() on an external path requires allow_url_fopen which as stated above is more commonly disabled.

    I hadn't thought of sockets.. I know that's a pain in the ass but it's worth a shot... So thank you! +rep to you my friend :)
     
    Chuckun, Jun 8, 2012 IP