没有讲清你的需求....理论上,php可以做成多线程的下载点.

解决方案 »

  1.   


    function getfilebodybinhttp($filename){
    eregi("^(http://)?([^/:]*):?([^/]*)?(.*)?",$filename,$fileparts);
    $port=($fileparts[3]=="")?80:intval($fileparts[3]);
    $strCommands="";
    $retBin=NULL;
    $body=NULL;
    $psize=1024;
    if($fphttp=fsockopen($fileparts[2],$port,$errno,$errstr,30)){

    $strCommands.= $this->Method." ".$fileparts[4]." HTTP/1.1\n";
    $strCommands.="Host:".$fileparts[2]."\n";
    $strCommands.="Accept:".$this->Accept."\n";
    $strCommands.="User-Agent:".$this->userAgent."\n";
    //$strCommands.="Pragma:no-cache\n";
    $strCommands.="Content-type: application/x-www-form-urlencoded\n";
    if($this->Cookie!="")
    $strCommands.= "Cookie:".$this->Cookie."\n"; 
    if($this->AcceptLanguage!="")
    $strCommands.="Accept-Language:".$this->AcceptLanguage."\n";
    $strCommands=$strCommands."Referer:".(($this->Referer=="")?$fileparts[2]:$this->Referer)."\n";
    $strCommands.="Connect:CLOSE\n";
    $strCommands.="\n";
    fputs($fphttp,$strCommands);
    //echo $strCommands."<p>";

    $crlf=chr(13).chr(10);
    $bodyEnd=chr(0).chr(0);
    while(($parts=fgets($fphttp)) && $parts!=$crlf && (substr($parts,-2)!=$bodyEnd))
    $head.=$parts;
    //eregi("Content-Length:([^\n]*)?.*",$head,$regs);
    //$filesize=intval($regs[1]);
    //$l=intval($filesize/$psize)+1;
    while(!feof($fphttp)){
    stream_set_timeout($fphttp, 60);
    $body .= fread($fphttp, 4096);
    $info = stream_get_meta_data($fphttp);
    if ($info['timed_out']) break;
    } fclose($fphttp);
    return $body;
    }
    }这是用fsockopen写的下载函数
    该如何去做多线程
      

  2.   

    运行多个进程,每个进程读一部分!
    主机是windows的 好像不支持pcntl_fork
    不知道如何实现多线程
      

  3.   

    100%不支持 而且多线程只能用在CLI方式
      

  4.   

    PHP的Apache SAPI能多线程吗?