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