PHP实现的支持断点续传的下载类

来源:互联网 发布:电脑网络异常怎么办 编辑:程序博客网 时间:2024/05/16 12:52

转自:http://www.jb51.net/article/55523.htm
断点续传测试方法:

使用linux wget命令去测试下载, wget -c -O file http://xxx

1.先关闭断点续传
$flag = $obj->download($file, $name);

test@ubuntu:~/Downloads$ wget -O test.zip http://demo.test.com/demo.php--2013-06-30 16:52:44-- http://demo.test.com/demo.php正在解析主机 demo.test.com... 127.0.0.1正在连接 demo.test.com|127.0.0.1|:80... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度: 10445120 (10.0M) [application/octet-stream]正在保存至: “test.zip”30% [=========>                                 ]3,146,580  515K/s 估时 14s^Ctest@ubuntu:~/Downloads$ wget -c -O test.zip http://demo.test.com/demo.php--2013-06-30 16:52:57-- http://demo.test.com/demo.php正在解析主机 demo.test.com... 127.0.0.1正在连接 demo.test.com|127.0.0.1|:80... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度: 10445120 (10.0M) [application/octet-stream]正在保存至: “test.zip”30% [=========>                                 ]3,146,580  515K/s 估时 14s^C 

可以看到,wget -c不能断点续传

2.开启断点续传

$flag = $obj->download($file, $name, true);test@ubuntu:~/Downloads$ wget -O test.zip http://demo.test.com/demo.php

--2013-06-30 16:53:19-- http://demo.test.com/demo.php
正在解析主机 demo.test.com... 127.0.0.1
正在连接 demo.test.com|127.0.0.1|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 10445120 (10.0M) [application/octet-stream]
正在保存至: “test.zip”

20% [=====> ] 2,097,720 516K/s 估时 16s
^C
test@ubuntu:~/Downloads$ wget -c -O test.zip http://demo.test.com/demo.php
--2013-06-30 16:53:31-- http://demo.test.com/demo.php
正在解析主机 demo.test.com... 127.0.0.1
正在连接 demo.test.com|127.0.0.1|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 206 Partial Content
长度: 10445121 (10.0M),7822971 (7.5M) 字节剩余 [application/octet-stream]
正在保存至: “test.zip”

100%[++++++++++++++++++++++++=========================================================================>] 10,445,121 543K/s 花时 14s

2013-06-30 16:53:45 (543 KB/s) - 已保存 “test.zip” [10445121/10445121])

0 0