php 有没有断点续传 http下载的类 没有讲清你的需求....理论上,php可以做成多线程的下载点. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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写的下载函数该如何去做多线程 运行多个进程,每个进程读一部分!主机是windows的 好像不支持pcntl_fork不知道如何实现多线程 100%不支持 而且多线程只能用在CLI方式 PHP的Apache SAPI能多线程吗? 如何学会php啊? php环境如何做成套件? php操作access数据库的问题,我一开始在php区问了,但是没人响应,所以过来碰碰运气,希望各位前辈给看看,万分感谢! 现在哪个php写的流量统计程序比较好 PHP+Mysql视频教程(共48集) PHP的域名查询类(不要小偷程序!谢谢!) 郁闷! 我用php写xml文件,怎么老是报错? PHP连接MSSQL的问题 php高手,来吧!交流无边界! thinkphp 3.2 视图模型 查询 出来bool(false) 求解 ms sql 中反斜杠注释出错问题,我的是php+ 将access数据库导入mysql后,中文显示乱码
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写的下载函数
该如何去做多线程
主机是windows的 好像不支持pcntl_fork
不知道如何实现多线程