Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实时速度等信息无法显示 #31

Closed
googles8 opened this issue Dec 28, 2017 · 4 comments
Closed

实时速度等信息无法显示 #31

googles8 opened this issue Dec 28, 2017 · 4 comments

Comments

@googles8
Copy link

设置
$curl->onInfo = array(
$toolkit,
'onInfo'
);
后报错。

开始下载...
E_WARNING: ErrorException: call_user_func() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in D:\WWW\1spider\mcurl\vendor\ares333\php-curl\src\Curl.php:415 Stack trace: #0 [internal function]: ErrorHandler::{closure}(2, 'call_user_func(...', 'D:\WWW\1spider\...', 415, Array) #1 D:\WWW\1spider\mcurl\vendor\ares333\php-curl\src\Curl.php(415): call_user_func(Array, Array, Object(Ares333\Curl\Curl)) #2 D:\WWW\1spider\mcurl\vendor\ares333\php-curl\src\Curl.php(288): Ares333\Curl\Curl->onInfo() #3 D:\WWW\1spider\shokdown.php(46): Ares333\Curl\Curl->start() #4 {main}

程序能正常执行,但会不停报上面的错误。信息也不能显示。

@ares333
Copy link
Owner

ares333 commented Dec 28, 2017

根据Demo无法重现问题,检查$toolkit对象是否有问题。
demo地址:https://github.com/ares333/php-curl/blob/master/demo/running_info.php

@googles8
Copy link
Author

googles8 commented Jan 1, 2018

感谢题主及明回复。 我用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

@ares333
Copy link
Owner

ares333 commented Jan 1, 2018

array(
    $toolkit,
    'onInfo'
);

$toolkit必须是Tookkit对象的实例,回调函数的具体用法看PHP手册:http://php.net/manual/en/function.call-user-func-array.php
//$curl->onInfo = null 注释掉显示运行状态是因为$curl对象由Toolkit初始化,默认设置了onInfo回调。

下载速度的计算规则是每隔一段时间根据已完成任务下载数据量和时间计算一次,所以要等有任务下载完毕。
实时计算需要考虑缓存等各种因素过于复杂没有实现,因为本类库的设计的目的处理是高并发大批量请求,所以认为没有必要去做这件事情(包括断点续传)。
如果有硬性需求可以通过继承等方式自行实现。

@googles8
Copy link
Author

googles8 commented Jan 1, 2018

感谢及时而有用的解答。终于明白了问题所在。
我用的$curl = (new Toolkit())->getCurl();因此,在调用时$toolkit的确不是实例。从而导致出错。
你这关注的果然是多线程的完成情况,在处理是高并发大批量请求时,这种考虑是对的。我开始是以为你这个也带了这种功 能。看了你的说明后,自己已经成功实现了下载大文件的实时进度显示。再次感谢

@ares333 ares333 closed this as completed Feb 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants