// callAmazonRESTWS.php
header("Content-type: text/xml");
$base = 'http://webservices.amazon.com/onca/xml';
$query_string = '';
$params = array(
'Service' =>'AWSECommerceService',
'SubscriptionId' => '16XT8ETKKB7NWHAGCQ02' ,
'Operation' => 'ItemSearch',
'SearchIndex' => 'Books',
'Keywords' => 'Web Services');
foreach ($params as $key => $value) {
if ($key != 'Keywords')
$query_string .= "$key=" . urlencode($value) . "&";
else
$query_string .="$key=".urlencode($value);
}
$url = "$base?$query_string";
// Define a context for HTTP.
$aContext = array(
'http' => array(
'proxy' => 'tcp://202.12.97.116:8080', // This is the sample server and the port of the proxys server.
'request_fulluri' => True,
),
);
$cxContext = stream_context_create($aContext);
// Now all file stream functions can use this context.
$xml = file_get_contents($url, False, $cxContext);
echo $xml;
>
You will get the result as shown on this picture.
References
* Roger L. Costello, “Building Web Services the REST Way”, http://www.xfront.com/REST-Web-Services.html
* Stefan Marr, “RESTful Web Services”, HPI, Seminar Advanced Database Technology
* Pete Freitag, “REST vs SOAP Web Services”, http://www.petefreitag.com/item/431.cfm
* Google, “Google SOAP Search API”, http://code.google.com/apis/soapsearch/
* Sameer Tyagi, “RESTful Web Services”, http://java.sun.com/developer/technicalArticles/WebServices/restful
Sunday, April 15, 2007
Sample PHP Codes Call Amazon Web Services
Automatically Backup MySQL Databases on Linux Server
We can automatically backup MySQL database on linux server by writing script and run cron. The cron command can run the script every x day at time y. The script use mysqldump in back up the database
The sample procedure is as follows
1. create script mysqldump.bsh which has it content as
#!/bin/bash mysqldump –user=”Database Username” –password=”Database Password” –all “Database Name” | gzip > “Full Path Where You Want Backup Saved”-`date +%Y%m%d`.gz
2. create file cron.txt
Assume that we want to backup the database at 6 am everyday
0 6 * * * /path/to/your/mysql_dump.bsh
There must be an empty line before the end of the file
3. run command "crontab cron.txt" to start the jobs specified in cron.txt
4. run command "crontab -l" to see the list of jobs currently scheduled and run on the system
References
http://www.bloggingpro.com/archives/2004/05/28/backing-it-up-or-lose-it/
http://en.wikipedia.org/wiki/Crontab
http://www.adminschoice.com/docs/crontab.htm