This article introduces, with PHP implementation of a multi-threaded download remote multiple files function, the need for a friend reference. The following code, implementation: Multi-threaded Download remote multiple files, as follows:
$V) {if (!empty ($v) && preg_match ("~^http~i", $v)) {$nurl [$k] = Trim (Str_replace (","%20 ", $v)); $curl [$k] = cur L_init ($nurl [$k]); curl_setopt ($curl [$k], curlopt_ipresolve, curl_ipresolve_v4); curl_setopt ($curl [$k], Curlopt_ Returntransfer, 1); curl_setopt ($curl [$k], Curlopt_header, 0); curl_setopt ($curl [$k], curlopt_connecttimeout,); if ( !isset ($handle)) {$handle = Curl_multi_init ();} Curl_multi_add_handle ($handle, $curl [$k]);} Continue;} $active = null;do{$MRC = @curl_multi_exec ($handle, $active);} while ($MRC = = Curlm_call_multi_perform) and while ($active &am p;& $MRC = = CURLM_OK) {if (Curl_multi_select ($handle)! =-1) {does {$MRC = Curl_multi_exec ($handle, $active);} while ($m rc = = Curlm_call_multi_perform);}} foreach ($curl as $k + $v) {if (Curl_error ($curl [$k]) = = "") {if ($k = = 0) {$fname [$k] = Strtolower ($name. '. '). PathInfo ($urls [$k], pathinfo_extension));} else {$fname [$k] = Strtolower ($name. '_' . $k. '.' . PathInfo ($urls [$k], pathinfo_extension));} $text [$k] = (striNG) curl_multi_getcontent ($curl [$k]); $filedir [$k] = $dir. '/'. $fname [$k];if (File_put_contents ($filedir [$k], $text [$k]) {$filepath [$k] = $path. $fname [$k];}} Curl_multi_remove_handle ($handle, $curl [$k]); Curl_close ($curl [$k]);} Curl_multi_close ($handle); return $filepath;}? > |