我目前正在尝试将数据从一台服务器发送到另一台服务器。它不是什么复杂的东西,只是一个很长的字符串(意思是~340 mb)。我已经尝试过多种方式,比如fopen()和/或cURL,但是从字符串大小的某个特定翻转点开始,$ _POST ['content']似乎一直是空的。这是我正在使用的代码:
$post_data['content'] = $sql;
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection =
curl_init('http://myIP/myDir/myscript.php');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//show information regarding the request
//print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' .
curl_error($curl_connection);
//close the connection
curl_close($curl_connection);`
接收脚本应该将内容写入我的数据库,因此它会临时将发布的字符串写入文件(因为出于性能原因,我需要使用加载数据本地文件):$myFile = "/my/path/to/file.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh,$_POST['content']);
fclose($fh);
有什么建议吗?
答案 0 :(得分:0)
您应使用http_build_query
函数创建查询字符串试试这个:
$post_string = http_build_query($post_data);