0
我目前正试图从一台服务器发送数据到另一台服务器。它并不复杂,只是一个非常长的字符串(意思是〜3-4 mb)。我已经尝试了多种方式,比如fopen()和/或cURL,但是从应该发送的字符串大小的某个滑动点开始,$ _POST ['content']看起来一直是空的。下面是我使用的代码:PHP programatic开机自检不起作用
$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);`
的recieving脚本应该写的内容到我的数据库,因此临时张贴的字符串写入到文件(因为我需要使用LOAD DATA LOCAL文件的性能原因):$myFile = "/my/path/to/file.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh,$_POST['content']); fclose($fh);
有什么建议吗?
您是否尝试过CURLOPT_POST'设置''到TRUE'?如果你有'CURLOPT_POSTFIELDS'中的任何东西,它假设将它设置为'TRUE',但那可能不起作用。 – NullUserException
也有你尝试发送一个较小的请求?您可能在任何一端都有大小限制。 – NullUserException
还要确保'post_items'数组的键和值是[urlencoded](http://php.net/manual/en/function.urlencode.php) – stewe