PHP文件\u获取\u内容发送大文章
我有以下方法发送PHP文件\u获取\u内容发送大文章,php,curl,file-get-contents,Php,Curl,File Get Contents,我有以下方法发送文件\u获取\u内容请求: protected function query($page, $post, $timeout = false, $debug = false, $enableWarnings = true) { $this->correctHostIfNeeded(self::HTTP_CONNECTION_TYPE); $page = $this->host . (substr($page, 0, 1) == '?' ? '' : '?
文件\u获取\u内容
请求:
protected function query($page, $post, $timeout = false, $debug = false, $enableWarnings = true) {
$this->correctHostIfNeeded(self::HTTP_CONNECTION_TYPE);
$page = $this->host . (substr($page, 0, 1) == '?' ? '' : '?') . $page;
$opts = array('http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
));
if (!empty($post)) {
$postdata = http_build_query($post);
$opts['http']['content'] = $postdata;
}
if ($timeout > 0)
$opts['http']['timeout'] = $timeout;
$context = stream_context_create($opts);
$result = $enableWarnings ? file_get_contents($page, false, $context) : @file_get_contents($page, false, $context);
return $result;
}
它通常工作得很好,比curl版本更好(它有时不能正确执行,不管post中的数据如何)。不幸的是,如果我发送非常大的POST-usign文件\u-get\u-contents
(例如,包含100k个元素的数组),它就会失败。有时,目标服务器会保存部分数据,但永远无法获取全部数据
我知道服务器之间的互联网连接不是问题(两台服务器都在我自己的数据中心中,两台服务器之间的速度稳定在100Mb左右)。另外,两台服务器上的代码本身似乎都很好,因为对于较小的数据,它可以正常工作,如果我改为
curl
则可以正确接收大的包(不幸的是,它有时会失败,我读到curl的行为并不奇怪)。尝试按部分读取文件,然后合并结果。在文件获取上下文中,您可以指定偏移量和最大长度参数。增加页面的执行时间,将其写在顶部-
ini_set('max_execution_time', 300);
我认为他的问题在于发送数据,而不是读取响应。你可能有道理。我不想在白天检查,所以我现在不知道是不是这样。