Showing posts with label Web Services. Show all posts
Showing posts with label Web Services. Show all posts

Tuesday 1 August 2017

Amazon Web Services Tutorial - Terminology

Amazon Web Services Tutorial - Basic understanding

Question: What is Amazon Web Services(AWS)?
AWS is Amazon's cloud web hosting platform that offers flexible, reliable, scalable, easy-to-use, and cost-effective solutions.


Question: What is cloud computing?
Cloud computing is an computing service in which large groups of remote servers are setup to allow centralized data storage, and online access to computer services or resources.


Question: What are the the benefits of Cloud Computing?
  1. AWS cost efficient
  2. Instantly setup of unlimited server
  3. Highly reliable
  4. Unlimited Storage
  5. Backup & Recovery
  6. Easy Access to Information



Question: What are the types of Cloud Computing?
  1. Public Cloud: Cloud computing services are managed by third party.
  2. Private Cloud: Cloud computing services are managed by own organization.
  3. Hybrid Cloud: Its combination of public cloud and private cloud.



Question: What are the Cloud Service Models of Cloud Computing?
  1. IaaS (Infrastructure as a Service): It provides users with provision of processing, storage, and network connectivity as per requirement.
  2. PaaS (Platform as a Service): The service provider provides various services like databases, queues, workflow engines, e-mails, etc. to their customers.
  3. SaaS (Software as a Service): Third-party providers provide end-user applications to their customers with some administrative capability at the application level.



Question: What is AWS EC2?
Full form of EC2 is Elastic Compute Cloud.
EC2 allow use virtual machines of different configurations as per their requirement.


Question: What is Load Balancing?
Load balancing means to balance the load on web server through adding resources on system. Load balancer manage the load on the server so that it work efficiently.


Question: What is Elastic Load Balancing?
Elastic Load Balancing is dynamically growing and shrinking the load-balancing capacity depending on server.


Question: What is Elastic Load Balancer?
It spread the traffic to web servers, which improves performance.
It is used to distributed the traffic to EC2 instances over multiple available zones, and dynamic addition and removal of Amazon EC2 hosts from the load-balancing rotation.


Question: What is Elastic Caches?
Amazon Elastic Cache is a web service that manages the memory cache in the cloud.


Question: What is Amazon RDS?
Relational Database Service (RDS) provides access of database like MySQL, Oracle, or Microsoft SQL Server database engine.


Question: What is AWS Management Console?
AWS Management Console is a web application for managing Amazon Web Services. It provide you detail about all servers and its resources, user billing/payment etc.


Question: What is Auto Scaling?
Auto Scaling is enabled by Amazon CloudWatch.
AWS CloudWatch can be used to measure CPU utilization, network traffic, etc.
When traffic increase then resource added automatically.


Question: What is Amazon Virtual Private Cloud?
Amazon VPC allows the users to use AWS resources in a virtual network.


Question: What services we can use with Amazon Virtual Private Cloud?
  1. Amazon EC2
  2. Amazon Route 53
  3. Amazon WorkSpaces
  4. Auto Scaling
  5. Elastic Load Balancing
  6. AWS Data Pipeline
  7. Elastic Beanstalk
  8. Amazon Elastic Cache
  9. Amazon EMR
  10. Amazon OpsWorks
  11. Amazon RDS
  12. Amazon Redshift



Question: What is Amazon Route 53?
It is a highly available and scalable DNS web service.
corporates to route the end users to Internet applications by translating human readable names like www.facebook.com, into the numeric IP addresses like 192.0.2.1.


Question: What is CloudFront?
CloudFront is a CDN retrieves data from Amazon S3 bucket and distributes it to multiple datacenter locations though edge locations.


Question: What is Amazon DynamoDB?
It is NoSQL database that allows to create database tables, store data in table and retrieve any amount of data.
It automatically manages the data traffic of tables over multiple servers and maintains performance.


Question: What is Amazon Redshift?
It is data warehouse service in the cloud. Its datasets range from 100s of gigabytes to a petabyte.


Question: What is Amazon Kinesis?
Amazon Kinesis is a managed, scalable, cloud-based service that allows real-time processing of streaming large amount of data per second.


Question: What is Amazon Elastic MapReduce?
Amazon Elastic MapReduce is a web service that provides a managed framework to run data processing frameworks such as Apache Hadoop, Apache Spark, and Presto in an easy, cost-effective, and secure manner.


Question: What is Amazon Pipeline?
AWS Data Pipeline is a web service, designed to make it easier for users to integrate data spread across multiple AWS services and analyze it from a single location.


Wednesday 15 March 2017

How to Send iOS push notification from PHP

How to Send iOS push notification from PHP?

PHP Code
//device token
$deviceToken = "a58c9e7406c4b591eda8f192027d00ef82cdba361821f693e7b8ac9cb3afbc61";

//Message will send to ios device
$message = 'this is custom message';

//certificate file
$apnsCert = 'pushcert.pem';
//certificate password
$passphrase = 1234;

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT, $ctx);


// Create the payload body
$body['aps'] = array(
    'badge' => +1,
    'alert' => $message,
    'sound' => 'default'
);

$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));

if (!$result)
    echo 'Message not delivered' . PHP_EOL;
else
    echo 'Message successfully delivered amar' . $message . PHP_EOL;

// Close the connection to the server
fclose($fp);



Question: What is full form of APNS?
Apple Push Notification Service


Question: What is device token in ios?
Device token is an identifier for the Apple Push Notification System for iOS devices.


Question: What is apnsHost for Development and LIVE?
Development Server
ssl://gateway.sandbox.push.apple.com:2195

Production Server
ssl://gateway.push.apple.com:2195



Question: From where we can test the APN Host?
http://pushtry.com/


Question: What port need to enable for APNs notification?
2195
2196
 



Monday 13 March 2017

IMAP Gmail read messages details from inbox

IMAP Gmail read messages details

Check that IMAP is turned on
If Not, Please enable.


Library Code

/** functions used for getting message **/
function flattenParts($messageParts, $flattenedParts = array(), $prefix = '', $index = 1, $fullPrefix = true) {

    foreach($messageParts as $part) {
        $flattenedParts[$prefix.$index] = $part;
        if(isset($part->parts)) {
            if($part->type == 2) {
                $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.', 0, false);
            }
            elseif($fullPrefix) {
                $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix.$index.'.');
            }
            else {
                $flattenedParts = flattenParts($part->parts, $flattenedParts, $prefix);
            }
            unset($flattenedParts[$prefix.$index]->parts);
        }
        $index++;
    }

    return $flattenedParts;
           
}


function getPart($con, $messageNumber, $partNumber, $encoding) {
   
    $data = imap_fetchbody($con, $messageNumber, $partNumber);
    switch($encoding) {
        case 0:
            return $data;
            break; // 7BIT
        case 1:
            return $data;
            break;// 8BIT
        case 2:
            return $data; // BINARY
            break;
        case 3:
            return base64_decode($data);  // BASE64
            break;
        case 4:
            return quoted_printable_decode($data); // QUOTED_PRINTABLE
            break;
        case 5:
            return $data; // OTHER
            break;
    }   
   
}


function getFilenameFromPart($part) {

    $filename = '';
   
    if($part->ifdparameters) {
        foreach($part->dparameters as $object) {
            if(strtolower($object->attribute) == 'filename') {
                $filename = $object->value;
            }
        }
    }

    if(!$filename && $part->ifparameters) {
        foreach($part->parameters as $object) {
            if(strtolower($object->attribute) == 'name') {
                $filename = $object->value;
            }
        }
    }
   
    return $filename;
   
}

/** functions used for getting message **/



How to read specific message
$username = 'mygmail@gmail.com'; //Gmail address
$password = 'gma12#@c'; //Gmail password
error_reporting(0);

 $bodyId=35; //This is message Id

 //Read Message from indebox
    $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
   
   //Read Message from Trash
    // $hostname = '{imap.gmail.com:993/imap/ssl}[Gmail]/Trash';
 
   //Read Message from Sent
 //$hostname = '{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail';




$con = imap_open($hostname, $username, $password);
$messageNumber = $bodyId;
$structure = imap_fetchstructure($con, $messageNumber);
//pr($structure);die;

$message='';
if(!empty($structure->parts)){
 
 $flattenedParts = flattenParts($structure->parts); 
 foreach($flattenedParts as $partNumber => $part) {  
  switch($part->type) {
     
   case 0:
    // the HTML or plain text part of the email
    $message = getPart($con, $messageNumber, $partNumber, $part->encoding);
    // now do something with the message, e.g. render it
      
   break;
    
   case 1:
    // multi-part headers, can ignore
    
   break;
   case 2:
    // attached message headers, can ignore
   break;
    
   case 3: // application
   case 4: // audio
   case 5: // image
   case 6: // video
   case 7: // other
   //pr($part);
   //echo "
$$$$$";
    $filename = getFilenameFromPart($part);
    if($filename) {
     // it's an attachment
     $attachment = getPart($con, $messageNumber, $partNumber, $part->encoding);
        if (empty($filename))
      $filename = $filename;
       
     if (empty($filename))
      $filename = time() . ".dat";
     $folder = "attachment";
     if (!is_dir($folder)) {
      mkdir($folder);
     }
     $fp = fopen("./" . $folder . "/" . $messageNumber . "-" . $filename, "w+");
     fwrite($fp, $filename);
     fclose($fp);
     // now do something with the attachment, e.g. save it somewhere
     $message.='

' . $messageNumber . '-' . $filename . '
'; } break; } } }else{ $message = getPart($con, $messageNumber, 1, $structure->encoding); } if($message){ $message=$message; } echo $message; imap_close($con, CL_EXPUNGE);



Thursday 11 August 2016

How to Convert Youtube Data API V3 video duration format to seconds in PHP?

How to Convert Youtube Data API V3 video duration format to seconds in PHP?

We get the youTube Video duration in below way from Youtube V3 API.
 "contentDetails": {
    "duration": "PT15S",
    "dimension": "2d",
    "definition": "sd",
    "caption": "false",
    "licensedContent": true,
    "projection": "rectangular"
   },

Now, We need to convert the duration to number of seconds.
Following are Simple PHP Function which convert the API V3 video duration format to number of seconds.
 function duration($ytDuration) {
    $di = new DateInterval($ytDuration);
    
    $totalSec = 0;
    if ($di->h > 0) {
      $totalSec+=$di->h*3600;
    }
    if ($di->i > 0) {
      $totalSec+=$di->i*60;
    }
    $totalSec+=$di->s;
    
    return $totalSec;
  }
$youtubeTime = 'PT15S';
 echo duration($youtubeTime);//15
 
 
$youtubeTime = 'PT2M55S'; 
echo duration($youtubeTime);//175

$youtubeTime = 'PT1H35M23S'; 
echo duration($youtubeTime);//5723

Wednesday 27 July 2016

How to detect and change Browser user agent?

How to detect and Browser user agent?

Question: What is Browser user agent?
It is software agent which acting on behalf of a user.
Actually it s user agent is a Single line of string which helps to detect the request. When an request is sent to web server then user agent of browser is also sent in header which helps the web server to identifying the browser and operating system.


Question: What is use of Browser user agent?
It helps the web server to identifying the browser and operating system.
Means with the help of user agent, web server can get the know which browser of OS is request the data.
Web site uses this customize content for the capabilities of a particular device.


Question: Who is using of Browser user agent?
Web Server (Websites) are using the user agent. With the help of user agent they get to know mobile OR Desktop.
then web server sent back the data as per requested device.


Question: How user agent is sent to Server?
When an browser send request to web server. then request header is sent to web server along with request data.


See Example of Request Header:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.5
Cache-Control:max-age=0
Connection:keep-alive
Cookie:user_segment=Prospect; _ga=GA1.2.1900507711.1469603080
Host:example.georama.loc
Referer:http://example.georama.loc/
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:47.0) Gecko/20100101 Firefox/47.0

User Agrent is
User-Agent:Mozilla/5.0 (Windows NT 6.1; rv:47.0) Gecko/20100101 Firefox/47.0
Above is user agent of mozilla having version 47.0


Question: What is my current user agent ?
http://www.useragentstring.com/


Question: How to detect Browser user agent?
with use of user agent string, you can detect the browser and OS. Open: http://www.useragentstring.com/ Add the user agent string and click on Analyse.


Question: Can we change Browser user agent? If Yes, How?
Yes, We can change the user agent.
With help of User-Agent Spoofing, We can change the user agent.


Question: What is User agent spoofing?
Spoofing means behave differently than in actuality.


Question: Who is User agent spoofing?
Spam bots, Web scrapers, hackers uses the spoofing to hide their identity.


Question: How to change the useragent in Chrome, Safari & Firefox?
http://osxdaily.com/2013/01/16/change-user-agent-chrome-safari-firefox/