Tuesday, October 30, 2012

Socket.io cannot connect to server Heroku

some times you might get following error with your socket.io applications deployed on heroku. like

error 
 or

Wednesday, May 30, 2012

Fix For Amazon API Error: Your request is missing required parameters. Required parameters include AssociateTag.

Amazon has made changes to there API which came effect since November 1st: 2011, and you might be getting following error when you made request to Product Advertising API.

Your request is missing required parameters. Required parameters include AssociateTag.



The fix is below

Sign up for Amazon Associates account.

get AssociateTag and pass it as parm in the request

eg:
[php]
$method = "GET";
$host = "ecs.amazonaws.".$region; // must be in small case
$uri = "/onca/xml";

$params["Service"] = "AWSECommerceService";
$params["AWSAccessKeyId"] = $public_key;
<strong>$params["AssociateTag"] = "your associate tag here ";</strong>
$params["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z");
$params["Version"] = "2009-03-31";

/* The params need to be sorted by the key, as Amazon does this at
their end and then generates the hash of the same. If the params
are not in order then the generated hash will be different thus
failing the authetication process.
*/
ksort($params);

$canonicalized_query = array();

foreach ($params as $param=&amp;gt;$value)
{
$param = str_replace("%7E", "~", rawurlencode($param));
$value = str_replace("%7E", "~", rawurlencode($value));
$canonicalized_query[] = $param."=".$value;
}

$canonicalized_query = implode("&amp;amp;", $canonicalized_query);

$string_to_sign = $method."\n".$host."\n".$uri."\n".$canonicalized_query;

/* calculate the signature using HMAC with SHA256 and base64-encoding.
The 'hash_hmac' function is only available from PHP 5 &amp;gt;= 5.1.2.
*/
$signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True));

/* encode the signature for the request */
$signature = str_replace("%7E", "~", rawurlencode($signature));

/* create request */
$request = "http://".$host.$uri."?".$canonicalized_query."&amp;amp;Signature=".$signature;

/* I prefer using CURL */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

$xml_response = curl_exec($ch);
[/php]

Thursday, May 17, 2012

configuring mongodb from php and Xampp

I was trying to use mongodb in one of my applications which is developed in PHP and codeigniter.and the dev env was xampp on my windows 7

I have chooses this library for interacting with mongodb from codeigniter http://getsparks.org/packages/mongodb/versions/HEAD/show as the instructions mentioned in the website i have copied config file and library file in the respective folders and when i was trying to insert some document data into the mongo db i was getting following error.

An Error Was Encountered

The MongoDB PECL extension has not been installed or enabled


below is the step by step guide to :
How to install MongoDB PECL extension in xampp and windows 7.

first download mongodb precompiled driver for php and windows 7 
https://github.com/mongodb/mongo-php-driver/downloads

choose the version to download based on the php version that you are using in xampp (go to localhost then you can see which version of php that you are using) if its 5.3x then go for https://github.com/downloads/mongodb/mongo-php-driver/mongo-1.2.4.zip.zip


Extract the contents and copy the file php_mongo.dll to your extension directory which you can find in php.ini file ( default location is  C:\xampp\php\ext) default location for php.ini is C:\xampp\php\php.ini)

once you have pasted the dll file in the extension directory open php.ini file and add the following line at the appropriate location


extension=php_mongo.dll



  

save the file and restart the Server. it should be working fine now.

Some of the common error that you might face; are
 PHP startup:mongo: Unable to initialize module
Module compiled with module API=10060613
PHP compiked with module API=20090626

which means you are using the wrong version of the dll file to that of your php version try with other versions and it should be fix.