How can server load be optimized when downloading files from a different domain in PHP?

When downloading files from a different domain in PHP, server load can be optimized by using the PHP cURL library to make the request asynchronously. This allows the server to continue processing other tasks while waiting for the file to download, reducing the overall load on the server.

$url = 'http://example.com/file-to-download.zip';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);

$data = curl_exec($ch);
curl_close($ch);

file_put_contents('downloaded_file.zip', $data);