Good day all.
I'm developing a basic script that posts images on tumblr, everything is working fine since I've developed the photoset posting.
actually, I'm using these 2 function in order to retrieve the oAuth:
function oauth_gen($method, $url, $iparams, &$headers) {
$iparams['oauth_consumer_key'] = CONSUMER_KEY;
$iparams['oauth_nonce'] = strval(time());
$iparams['oauth_signature_method'] = 'HMAC-SHA1';
$iparams['oauth_timestamp'] = strval(time());
$iparams['oauth_token'] = OAUTH_TOKEN;
$iparams['oauth_version'] = '1.0';
$iparams['oauth_signature'] = oauth_sig($method, $url, $iparams);
$oauth_header = array();
foreach($iparams as $key => $value) {
if (strpos($key, "oauth") !== false) {
$oauth_header []= $key ."=".$value;
}
}
$oauth_header = "OAuth ". implode(",", $oauth_header);
$headers["Authorization"] = $oauth_header;
}
function oauth_sig($method, $uri, $params) {
$parts []= $method;
$parts []= rawurlencode($uri);
$iparams = array();
ksort($params);
foreach($params as $key => $data) {
if(is_array($data)) {
$count = 0;
foreach($data as $val) {
$n = $key . "[". $count . "]";
$iparams []= $n . "=" . rawurlencode($val);
//$iparams []= $n . "=" . $val;
$count++;
}
} else {
$iparams[]= rawurlencode($key) . "=" .rawurlencode($data);
}
}
$parts []= rawurlencode(implode("&", $iparams));
//debug($parts,"parts");
//die();
$sig = implode("&", $parts);
return base64_encode(hash_hmac('sha1', $sig, CONSUMER_SECRET."&". OAUTH_SECRET, true));
}
the bold line is the one that gives the out of memory error on the server, I've actually 68Mb of memory that I cannot modify, I've noticed this:
if I want to post let's say 4 images, I pass an array with the binary content of the images, which could be about 4Mb (let's say about 1Mb for each image), but once the data is beeing urlencoded, this data become more than 12Mb.
this is an example, just to understand:
this is the first bytes of an image:
?? JFIF ??
?? ?? k ??
??
the urlencoded string is:
%EF%BF%BD%EF%BF%BD+%10JFIF+%01%01++%01+%01++%EF%BF%BD%EF%BF%BD+%03%02%02%02%02%02%03%02%02%02%03%03%03%03%04%06%04%04%04%04%04%08%06%06%05%06%09%08%0D%0A%0D%0A%09%08%09%09%0D%0A%0C%0F%0C%0D%0A%0B%0E%0B%09%09%0D%0A%11%0D%0A%0E%0F%10%10%11%10%0D%0A%0C%12%13%12%10%13%0F%10%10%10%EF%BF%BD%EF%BF%BD%01%03%03%03%04%03%04%08%04%04%08%10%0B%09%0B%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%10%EF%BF%BD%EF%BF%BD%08%02k%02%1C%03%01%11+%02%11%01%03%11%01%EF%BF%BD%EF%BF%BD+++%07%01%01%01%01++++++++++%02%03%04%05%06%07%01%08%09%0D%0A%EF%BF%BD%EF%BF%BD%10+%02%01%03%02
this is very very long, for a bunch of bytes...
does anyone has faced this problem? does anyone has some clues on how solve it? is it possible to solve it?