Reputation: 1312
I have a mail address on my server which receives emails and pipes them to a php script - piper.php
This script then parses the email and retrieves from, to, subject and message parts correctly. Once that is complete, I'd like this script to post this information to a remote CakePHP website to be stored in a MySQL database. I have all of this working except for the posting part.
To post, I use the code given at this link using cURL but I have two questions (code is below for reference only)
function curl_post_async($url, $params)
{
foreach ($params as $key => &$val) {
if (is_array($val)) $val = implode(‘,’, $val);
$post_params[] = $key.’=’.urlencode($val);
}
$post_string = implode(‘&’, $post_params);
$parts=parse_url($url);
$fp = fsockopen($parts[‘host’],
isset($parts[‘port’])?$parts[‘port’]:80,
$errno, $errstr, 30);
pete_assert(($fp!=0), "Couldn’t open a socket to ".$url." (".$errstr.")");
$out = "POST ".$parts[‘path’]." HTTP/1.1\r\n";
$out.= "Host: ".$parts[‘host’]."\r\n";
$out.= "Content-Type: application/x-www-form-urlencoded\r\n";
$out.= "Content-Length: ".strlen($post_string)."\r\n";
$out.= "Connection: Close\r\n\r\n";
if (isset($post_string)) $out.= $post_string;
fwrite($fp, $out);
fclose($fp);
}
The code uses URL encoding - I am concerned that this may not work if , for example, my email message exceeds 1MB in text - arent there limits on the size of data that can be sent via URL encoding?
Is there a better way of doing this? Should I establish a PERL script to directly connect to the Remote MySQL database and write? Suggestions are welcome
Upvotes: 1
Views: 1525
Reputation: 15464
It's not the CURL.
Server has its own post restrictions(Apache for example: http://httpd.apache.org/docs/2.2/mod/core.html#LimitRequestBody). And your php instance could have other options http://php.net/manual/en/ini.core.php#ini.post-max-size.
It's up to you to deside what to do. Both ways seems legit.
Upvotes: 1