Wednesday, September 16, 2015

Phantomjs Failing to Open Https Site - SSL Handshake Failed

Phantomjs Failing to Open Https Site - SSL Handshake Failed

I am using Phantom JS for scrapping sites. During scrapping I faced some issue with Phantom JS (Webpage module). Phantom JS site has very less details about Web Page module.

So, here is some more information about Phantom JS Web Page module : 

How to Use Web Page Module using Phantom JS

Web Page module has been used mostly for scrapping the data from a website.

    var webPage = require('webpage'); 
    var page = webPage.create();
    page.open('url', function(status){
    })

How to debug Web Page Module?

When you use web page module and if any issue come then web page module do not show any error it simply give status fail.

But you can do couple of thing for understanding the issue. 
Before the page.load you use following code for getting the error :
         
          page.onResourceError = function(err) { 
          page.reason = err.errorString;
page.cause_url = err.url; 
           } 


Now you can print the reason inside page.open.

page.open('url', function(status) {
         if ( status == 'fail' ) {
              console.log(page.reason);
              console.log(page.cause_url);
         }
})

How to solve "SSL Handshake Failed" issue?


If you are getting "SSL Handshake Failed" issue then you should run the Phantom JS script with following command. One of them should solve your issue :
  1. phantomjs --ignore-ssl-errors=true test.js
  2. phantomjs --ignore-ssl-errors=true --ssl-protocol=tlsv1 test.js

Enjoy :)

What is Composer? Why do we need Composer for Php development?

What is Composer? Why do we need Composer for Php development?

If you are doing development in Php then you might always face a issue whenever you are handling with 3rd party libraries. Integration and configurations of 3rd party library is always a headache in Php. For configuration you will have to read the documentation of 3rd party library. It resolve the dependency of a package.

But this has been easy after introduction of Composer.

Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.
Composer is just a command line tool which helps you to manage dependency for Php. Remember it is not a package manager tool. It is very easy to learn.

Composer helps you to solve following problems : 

  • It resolves the dependency of a package : Suppose you are installing one package for Mongo DB and you do not know the dependency of this package. If you use Composer it will resolve the dependency and install it.
  • Command line tool : Good for developers. You just have to configure a JSON file, run the command and you are done. Rest of the things will be handled by Composer. Ex: Suppose you want to install Monolog in your project then configure the composer.json
{
    "require": {
        "monolog/monolog": "1.2.*"
    }
}
  • Version : You do not have to worry about the version of library. You just provide the version number or provide *. If you are providing version number then it will install that particular version otherwise the latest version.
System Requirement for Composer:  

You need 5.3.0+ version of Php.