Php 卷曲响应内容不完整

Php 卷曲响应内容不完整,php,curl,Php,Curl,我正在使用api(使用curl和php),它应该根据日期返回一批csv记录。首先,发出一个请求,返回批处理中的记录数。第二个请求是实际检索记录。我的问题是,当我发出第二个请求时,我没有得到第一个请求指示我要得到的记录数。无论选择哪一天,我都会得到7167条记录(任何一天的记录数都会超过8000条)。我收到的内容长度是标题中表示我要获取的内容长度。我没有得到任何错误。问题是,如果我把url请求放在浏览器的地址栏中,我会得到所有应该得到的记录 该脚本在linux平台上运行。事实上,我已经在另一台li

我正在使用api(使用curl和php),它应该根据日期返回一批csv记录。首先,发出一个请求,返回批处理中的记录数。第二个请求是实际检索记录。我的问题是,当我发出第二个请求时,我没有得到第一个请求指示我要得到的记录数。无论选择哪一天,我都会得到7167条记录(任何一天的记录数都会超过8000条)。我收到的内容长度是标题中表示我要获取的内容长度。我没有得到任何错误。问题是,如果我把url请求放在浏览器的地址栏中,我会得到所有应该得到的记录

该脚本在linux平台上运行。事实上,我已经在另一台linux服务器上试用过,结果也一样。我已尝试更改执行时间和超时设置。我真的很困惑。提前感谢您的建议

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
set_time_limit(0);  // no limit

$username = "*********";
$pwd = "*********";

$urlCount = "https://*********&fromDate=". $today . "&toDate=" . $tomorrow";
$TotalPages = 0;
$CurrentPage = 0;
$PageSize = 1;
$RecordCount = 0;
$TotalRecordsProcessed = 0;

$today = date( "Y-m-d" );
$tomorrow = date( 'Y-m-d', strtotime( "+1 days" ) );

echo "today " . $today . "<br>";
echo "tomorrow: " . $tomorrow . "<br>";

$urlCount = "https://*********&fromDate=". $today . "&toDate=" . $tomorrow;

$headers = array("Content-Type:text/plain", 'Connection: Keep-Alive');

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlCount );// Get the count of the records we asked for
curl_setopt($ch, CURLOPT_HEADER, true );
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true );
curl_setopt($ch, CURLOPT_TIMEOUT, 6000);
curl_setopt($ch, CURLOPT_VERBOSE, true );
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $pwd );

$result = curl_exec( $ch );                             // execute the curl function

$lines = explode( "\r\n", $result );
$idx = 0;
while( $lines[ $idx ] != null ) $idx++;     // find the empty line
$RecordCount = $lines[ $idx + 1 ];          // This is the index to the number of records in the set
$PageSize = $RecordCount;

echo "Records in set: " . $RecordCount . "<br>";

$url = "https://***********&fromDate=2015-10-19&toDate=2015-10-20&pageSize=" . $PageSize . "&pageNumber=" . $CurrentPage . "&timezone=Eastern&outputType=csv";

curl_setopt($ch, CURLOPT_URL, $url );       // set the url for getting the records

$result = curl_exec( $ch );                 // execute the function

$info = curl_getinfo($ch);

curl_close( $ch );

$size_download = $info["size_download"];
echo "Http Code: " . $info['http_code'] . "<br>";
echo "Size download: " . $info["size_download"] . "<br>";

// Make sure the length of the content received is the same as the "size_download" from the http header
$pos = strpos( $result, "UUID" ) - 2;       // find the begining of the content
$result = substr( $result , $pos, -1 );     // remove the header data...keep just the content
$len = strlen( $result );                   // get the length of the received content
if( $len != $size_download )
{
    echo "length:" . strlen( $result ) . "<br>";
    echo "Content recieved not = size_download<br>";
}

// Check to make sure records downloaded match the number of records that the first curl request says there are
// Records are in csv format

$lines = explode( "\r\n", $result );
$RecordsReceived = count( $lines );
if( $RecordsReceived != $RecordCount )
{
    echo "Record Count = " . $RecordCount . " RecordsReceived = " . $RecordsReceived . "<br>";
}

?>

作为第一个建议,您是否正确计算行数?似乎
$RecordCount=count($lines)
比在8000项数组中循环查找不太可能找到的
null
效果更好。此外,我会尝试将curl结果转储到文件中,查看其内容是否符合您的期望。是的,记录计数是准确的。标题信息和发送的内容之间有一个空行。那段代码找到了那条空行。然后增加索引,使其位于返回内容的开头。是的,我已经放弃了结果。明白了,我明白了,这是你得到详细信息的第一个请求。是否确定数据中的所有行都以
\r\n
结尾?是。我已经将内容(在进行分解之前)写入一个文件,然后导入excel,两者中的记录数相同。所有记录的字段数都正确。没有任何合并记录。作为第一个建议,您是否正确地计算行数?似乎
$RecordCount=count($lines)
比在8000项数组中循环查找不太可能找到的
null
效果更好。此外,我会尝试将curl结果转储到文件中,查看其内容是否符合您的期望。是的,记录计数是准确的。标题信息和发送的内容之间有一个空行。那段代码找到了那条空行。然后增加索引,使其位于返回内容的开头。是的,我已经放弃了结果。明白了,我明白了,这是你得到详细信息的第一个请求。是否确定数据中的所有行都以
\r\n
结尾?是。我已经将内容(在进行分解之前)写入一个文件,然后导入excel,两者中的记录数相同。所有记录的字段数都正确。没有任何合并记录。