Use pocketmine\utils\Utils::getURL() if you want to download and process the data like JSON or other APIs. You can also file_put_contents() the result. You can also use copy("http://example.com", "one.file") to copy, as long as the connection is not HTTPS. If it is HTTPS, you must use cURL (Utils::getURL()). Remember, this call usually takes more than 0.1 second, which is considered as "slow" and "blocking", and should be run in an AsyncTask or a separate Thread. Blocking calls take more than one tick, and they will "overload" the server. Always use an AsyncTask when doing these things.
As I said, it is a thread-blocking operation. That means the line after the function won't be executed (and the whole server will hibernate except other threads) until the download ends. That's why you have to use an AsyncTask. Example plugin: (Will post later)
plugin.yml: Code: name: Downloader author: PEMapModder version: 0.0 api: 1.0.0 main: downloader\DownloaderPlugin commands: dl: usage: /dl <URL> <name> description: Downloads a file from <URL> to plugin data folder/<name> src/downloader/DownloaderPlugin.php: PHP: <?phpnamespace downloader;class DownloaderPlugin extends \pocketmine\plugin\PluginBase{ public function onCommand(\pocketmine\command\CommandSender $sender, \pocketmine\command\Command $c, $l, array $args){ // missing: only execute the following code after confirming $c->getName() is "dl" if(!isset($args[1])) return false; // if not enough arguments, send usage and exit command $to = $this->getDataFolder() . "downloads/$args[1]"; @mkdir(dirname($to), 0777, true); // create the directory for the file to be saved if it doesn't already exist $this->getServer()->getScheduler()->scheduleAsyncTask(new DownloadTask($args[0], $this->getDataFolder() . $args[1], $this, $sender)); // add the AsyncTask to the server scheduler's async task pool }} src/downloader/DownloadTask.php: PHP: <?phpnamespace downloader;class DownloadTask extends \pocketmine\scheduler\AsyncTask{ private $from, $to; private $plugin; private $sender; public function __construct($from, $to, DownloaderPlugin $plugin, \pocketmine\command\CommandSender $sender){ // initialize fields $this->from = $from; $this->to = $to; $this->plugin = $plugin; $this->sender = $sender; } public function onRun(){ $start = microtime(true); $result = \pocketmine\utils\Utils::getURL($this->from); // download data from the URL. This function call blocks. $end = microtime(true); // ($end - $start) is the number of seconds (decimal numbers) used to download data. if(!is_string($result)){ $this->setResult(false); // if $result is not a string, the download must have failed. Set the result to false to remember that it failed. return; } file_put_contents($this->to, $result); // save $result to the target file $this->setResult(true); // Set the result to true to remember that it has success. } public function onCompletion(\pocketmine\Server $server){ if($this->getResult() === true){ // upon success $this->sender->sendMessage("File downloaded from $this->from, saved at $this->to"); }else{ // upon failure $this->sender->sendMessage("For some reason, downloading from $this->from to $this->to failed."); } }}