cURL not working with PocketMine

Discussion in 'Development' started by HittmanA, Nov 21, 2016.

  1. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    I am trying to use cURL in a plugin but it doesn't seem to work. code:
    PHP:
    $plugin $args[0];
            
    $sender->sendMessage($args[0]);
            
    set_time_limit(0);
            
    $url "https://pmpm-hittmana.c9users.io/plugins/download/$plugin.zip";
            
    $sender->sendMessage($url);
            
    //This is the file where we save the    information
            
    $fp fopen ("$plugin.zip"'w+');
            
    $sender->sendMessage(dirname("../$plugin.zip"));
            
    //Here is the file we are downloading, replace spaces with %20
            
    $ch curl_init(str_replace(" ","%20",$url));
            
    curl_setopt($chCURLOPT_TIMEOUT120);
            
    curl_setopt($chCURLOPT_FILE$fp);
            
    // get curl response
            
    curl_exec($ch);
            
    curl_close($ch);
            
    fclose($fp);
    $args[0] is ArmorSpawn and I have confirmed that I can download it both on a browser and if I run the above code modified for native php. The problem is that it does not write anything to the file that is created. The file is there but it is 0 bytes. Why does my cURL request not work?
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,157
    GitHub:
    Thunder33345
    remove set time limit,
    NOTE c9 web server don't run forever unless you have that some plan the free plan server shuts off after some time
    maybe try ../$plugin
    and some times you have to hack it to make download work
    since it is dependent on server
     
    HittmanA and applqpak like this.
  3. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    Ok thanks!
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,876
    GitHub:
    sof3
    curl_error() and CURLOPT_HTTPHEADER may help you find out issues.
     
    Thunder33345 likes this.
  5. imYannic

    imYannic Baby Zombie

    Messages:
    113
    cURL doesnt work on local android and iOS PocketMine servers, not sure if it is the same in windows.
     
  6. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,374
    GitHub:
    robske110
    cURL does work on windows
     
  7. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    Then what is a cross-platform cURL solution?
     
  8. imYannic

    imYannic Baby Zombie

    Messages:
    113
    On local servers too?
     
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,157
    GitHub:
    Thunder33345
    curl should work if it is installed
     
  10. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    Is it safe to use cURL or isn't it?
     
  11. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,157
    GitHub:
    Thunder33345
    depends what you are doing with it most times
     
  12. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    GETing a webpage
     
  13. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,157
    GitHub:
    Thunder33345
    and how do you think that is dangerous?
    unless you do eval or system or exec everything you get there no harm
    just like web browser with js disabled loading a webpage
     
  14. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    I never said that I thought it was dangerous :p
     
    Thunder33345 likes this.
  15. Reid

    Reid Spider Jockey

    Messages:
    43
    You asked is it safe wouldn't that imply that you thought it could be dangerous??
     
    Thunder33345 likes this.
  16. HittmanA

    HittmanA Zombie

    Messages:
    207
    GitHub:
    hittmana
    I only meant that all (or most) platforms should be able to use it. Therefore I meant a plugin won't break because it uses cURL
     
  17. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,876
    GitHub:
    sof3
    cURL is part of standard PHP extensions, bundled with default PHP downloads on Windows, i.e. it is an official extension (implying that it is better than YAML or pthreads which aren't bundled with default PHP downloads). If individual systems like PHP for Android don't work with them, it is their problems.
     
    HittmanA likes this.
  18. imYannic

    imYannic Baby Zombie

    Messages:
    113
    Doesnt pocketmine on android use the normal PHP version?
     
  19. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,374
    GitHub:
    robske110
    What do you mean by local servers?
     
  20. imYannic

    imYannic Baby Zombie

    Messages:
    113
    Servers which are hosted on your device and not by a hosting company
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.