Comments (4)
根据Demo无法重现问题,检查$toolkit对象是否有问题。
demo地址:https://github.com/ares333/php-curl/blob/master/demo/running_info.php
from php-curl.
感谢题主及明回复。 我用running_info.php测试也可以正常。但我想要的是在下载时可以及时显示,于是我将demo/download.php中,$curl->onInfo = null; 换成了$curl->onInfo = array(
$toolkit,
'onInfo'
);
就报上面的错误。
经测试,不加上面的,而是将//$curl->onInfo = null; 注释掉,则可以显示。为什么会有这个不同?
而且发现,一个文件在下载的过程中,它的数值一直是0.
SPD:0KB DWN:0MB FNH:0 CACHE:0 RUN:1 ACTIVE:1 POOL:49 QUEUE:0 TASK:50 FAIL:0
只有该线程下载完成了,它的信息也会显示出数据来。
也就是说,它的信息是多线程下载中,某个线程下载完成后,它的信息。
这与想要的,在下载时,实时显示当时的速度等信息还是不同的。而一个大文件下载过程中,是需要实时知道已经下了多少,速度多少。
能针对这种显示吗?
SPD:0KB DWN:0MB FNH:0 CACHE:0 RUN:1 ACTIVE:1 POOL:49 QUEUE:0 TASK:50 FAIL:0
SPD:0KB DWN:0MB FNH:0 CACHE:0 RUN:1 ACTIVE:1 POOL:49 QUEUE:0 TASK:50 FAIL:0
SPD:200KB DWN:1MB FNH:7 CACHE:0 RUN:1 ACTIVE:1 POOL:42 QUEUE:0 TASK:50 FAIL:0
SPD:323KB DWN:2MB FNH:15 CACHE:0 RUN:1 ACTIVE:1 POOL:34 QUEUE:0 TASK:50 FAIL:0
SPD:407KB DWN:3MB FNH:23 CACHE:0 RUN:1 ACTIVE:1 POOL:26 QUEUE:0 TASK:50 FAIL:0
SPD:531KB DWN:4MB FNH:32 CACHE:0 RUN:1 ACTIVE:1 POOL:17 QUEUE:0 TASK:50 FAIL:0
SPD:614KB DWN:5MB FNH:41 CACHE:0 RUN:1 ACTIVE:1 POOL:8 QUEUE:0 TASK:50 FAIL:0
SPD:746KB DWN:6MB FNH:50 CACHE:0 RUN:0 ACTIVE:0 POOL:0 QUEUE:0 TASK:50 FAIL:0
from php-curl.
array(
$toolkit,
'onInfo'
);
$toolkit必须是Tookkit对象的实例,回调函数的具体用法看PHP手册:http://php.net/manual/en/function.call-user-func-array.php
//$curl->onInfo = null 注释掉显示运行状态是因为$curl对象由Toolkit初始化,默认设置了onInfo回调。
下载速度的计算规则是每隔一段时间根据已完成任务下载数据量和时间计算一次,所以要等有任务下载完毕。
实时计算需要考虑缓存等各种因素过于复杂没有实现,因为本类库的设计的目的处理是高并发大批量请求,所以认为没有必要去做这件事情(包括断点续传)。
如果有硬性需求可以通过继承等方式自行实现。
from php-curl.
感谢及时而有用的解答。终于明白了问题所在。
我用的$curl = (new Toolkit())->getCurl();因此,在调用时$toolkit的确不是实例。从而导致出错。
你这关注的果然是多线程的完成情况,在处理是高并发大批量请求时,这种考虑是对的。我开始是以为你这个也带了这种功 能。看了你的说明后,自己已经成功实现了下载大文件的实时进度显示。再次感谢
from php-curl.
Related Issues (12)
- 如何防止出现 403 问题 HOT 1
- 图片下载零字节 HOT 2
- Fatal error: url is invalid HOT 1
- 克隆网站到2G,一直没结束 HOT 1
- 下载后所有的中文都是Unicode HOT 3
- 请问添加任务之后,怎么获取抓取到的内容? HOT 2
- Undefined index: scheme HOT 5
- 为什么现在无法访问的连接不会返回任何东西,无法在代码中通过http_code判断该连接是否能正常访问$value = $args['url']; $http_code = $r['info']['http_code']; if($http_code !== 200){//判断能否请求 return $this->code('70001',['error_link'=>$value,'data'=>$value]); } HOT 1
- The args parameter is set to unavailable. HOT 3
- sorry. please delete this issue HOT 2
- Core.php Line:559 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-curl.