如何为所有网址设置curl_setopt以使用curl下载网址?

There are many urls to be downloaded.

 foreach ($urls as $key => $url){
    $path = $path .strval($key);
    $curl = curl_init();
    curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,0);
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLINFO_HEADER_OUT, 1);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_URL, $url);
    $data=curl_exec($curl);
    file_put_contents($path, $data);
    curl_close($curl);
    }

All the urls can be downloaded with the code,some statements executed for every url such as :

    $curl = curl_init();
    curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,0);
    curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt($curl, CURLINFO_HEADER_OUT, 1);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

Could the repeaded curl_setopt statements be simplified?How to simplify the code?

You are never executing your Curl request curl_exec($curl); So you are not even using Curl. If your code is working like this, you don't need any of those options. Then you can simplify your code to:

foreach ($urls as $key => $url){
    $path = $path .strval($key);
    $data=file_get_contents($url);
    file_put_contents($path, $data);
    }