I’m currently trying to send data from one server to another. It isn’t anything complex, just a very long string (which means ~ 3-4 mb). I already tried multiple ways like fopen() and/or cURL but from a certain klipping point in the size of the string that should be send the $_POST[‘content’] appears to be empty all the time. Here’s the code that I’m using:
$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);`
The recieving script should write the content into my database, therefore it temporary writes the posted string into an file (cause I need to use Load Data Local In File for performance reasons):$myFile = "/my/path/to/file.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh,$_POST['content']);
fclose($fh);
Any suggestions?
You shall use
http_build_queryfunction to create a query string try this: