PHP curl_multi_getcontent partial body received

懵懂的女人 提交于 2020-01-05 17:23:42

问题


I'm struggling on this problem.

The body I am fetching is not a big one, 3100 chars. Apache logs on the server says the content length was 3100. However, the string returned by curl_multi_getcontent was cut to 1290 characters.

Usually curl_multi_getcontent() works fine, but sometimes we get this weird behaviour.

Any ideas?


回答1:


This one kicked my butt. It seems to be a bug in php5's (multi?)curl system. I encountered this bug while using the rolling-curl multicurl lib, but the underlying problem seems to be in php itself. Here's my php -v:

PHP 5.3.3-1ubuntu9.3 with Suhosin-Patch (cli) (built: Jan 12 2011 16:07:38) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

Under some circumstances (in my case CURLOPT_TIMEOUT was being maxed) curl_error and curl_errno would not properly report an error in the curl. I had to use the 'result' key from the array returned by curl_multi_info_read. That result code gave me the actual error number when the curl_err* functions reported everything as normal.

I think this problem is related to this bug report: http://bugs.php.net/bug.php?id=52558




回答2:


My code was missing the check for transfers in progress.

With transfers in progress:

http_code = 200
errno = 0
download_content_length = total length, e.g. 1M
size_download = current position, <= download_content_length

Seems the while( curlm_multi_exec == CURLM_CALL_MULTI_PERFORM ) is somewhat insufficient. We have to loop with usleep until sizes match for this url or multi_exec second argument announces all urls finished.

Steps to reproduce:

  • PHP < 5.2, One url with transfer time of several seconds.


来源:https://stackoverflow.com/questions/4780741/php-curl-multi-getcontent-partial-body-received

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!