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.


Friday, December 21, 2012

How to override default database value in form field?


Creation of form in Yii is very easy. You can create it very easily. But sometime it will be headache for you if you are unknown with some features.

Ex : Suppose you have some default value for some column in a table. And you want to create a Create form. Some time it is good to display default values but not always. So, this default value can irritate you.

How to remove default value???

Simple, go to the model class corresponding to your form and add

public $columnNameOne = null;
public $columnNameTwo = null;

Note : You have to include these lines on class level not method level.

Now the above columns will not show default values in form.

How to generate crud, models or forms in Modules


How to generate crud, models or forms in Modules ?
This is simple but tricky for novice. If you have good understanding of path in YII (or in any computer language) then you can easily understand it. 
Okey , let's start :
These are keywords which are use in Yii framework :  
  • system : Refers to the Yii framework directory.
  • zii: Refers to the Zii library directory.
  • application: Refers to the application's base directory. Using this you can point your base directory. You can say this will be root directory of all directories of your project.
  • webroot: Refers to the directory containing the entry script file.
  • ext: Refers to the directory containing all third-party extensions.
Example: Suppose you have to access models of modules 'Group'. Let say directory structure is :

/opt/lampp/htdocs/TestProject/modules/model/testmodle.php

and you want to get reference of "testmodel.php" file in your program. One solution is you just give the full path of "testmodel.php" . But suppose after sometime you want to move your project to another machine then you there you will get error. Because system will never find the above path.

So, what is the solution???

Think...
Think...
Again Think...

Ya, you got it. You need to provide relative path. Yii framework provides very good solution for this. Now you can refer the above describe alias path. 

Solution : application.module.model.testmodel.php

 I think it is clear for you. Now come to the core question. How we can generate models/crud/form under a modules.   

  1. Create a module using Gii tool.
  2. Register your module name in the config main.php 
  3. Create a model via Model Generator. Fill in the fields and put this in Model Path : application.modules.[module-name].models
  4. Create crud via Crud Generator. Fill in the fields and put this in Model Class: application.modules.[module-name].models.[model-name]
The above example was for models. Similarly you can use for crud or form.  

Friday, November 30, 2012

Yii Bootstrap Issue 

Twitter Bootstrap is a CSS Framework. It is provided by Twitter. This Framework has provided a lot of predefined CSS code. Using these code you can easily and fast you can build and design your website. So basic of this Framework is less code more effect. Here you can find :

  • Well define form structure
  • Good and attractive Button design
  • Support of Jquery Library
  • Support of Less code
  • Etc...
Here I am not trying to enplane Bootstrap Framework. There is already well documentation is present on the INTERNET.

Yii also support Bootstrap i.e Bootstrap integration with Yii framework has already been done.  You can find details here : Yii Bootstrap .

Ok , so I am here explain some issue which I use to get during development.

Issue 1 (Table) :
This issue I got when I was trying to display a table with some content.  

Example :


$gridDataProvider = new CArrayDataProvider(array(
    array('id'=>1, 'firstName'=>'Mark', 'lastName'=>'Otto', 'language'=>'CSS'),
    array('id'=>2, 'firstName'=>'Jacob', 'lastName'=>'Thornton', 'language'=>'JavaScript'),
    array('id'=>3, 'firstName'=>'Stu', 'lastName'=>'Dent', 'language'=>'HTML'),
));

$this->widget('bootstrap.widgets.TbGridView', array(
    'type'=>'striped bordered condensed',
    'dataProvider'=>$gridDataProvider,
    'template'=>"{items}",
    'columns'=>array(
        array('name'=>'id', 'header'=>'#')
        array('name'=>'firstName', 'header'=>'First name'),
        array('name'=>'lastName', 'header'=>'Last name'),
        array('name'=>'language', 'header'=>'Language'),
        ),
));


If you print this on it will not through any error. But if you change 'id' to something else then it will through a error.

Error :

Undefined index: id

Solution

So, Here only solution for solving this you will have to always put 'id'.

Key :  Bootstrap, Yii Framework ,

Friday, October 5, 2012

Introduction

Yii Framework is a High Performance Php framework which follows MVC pattern. This framework is combination of different features like :
  • MVC Pattern
  • Cache Management
  • Security
  • DAO/Active record 
  • Scaffolding
  • Testing/Debugging
  • High performance/Fast coding  
 Yii framework can easily be integrated with different databases like MySql, Postgresql, Oracle , DB2 etc.

Installation

Installation of Yii Framework is very easy.These are the requirements for YII framework setup :
  • LAMPP Package.
  • YII Framework Package.
  • Operating System. 
 LAMPP :

According to Wikkipedia this is is a free and open source cross-platform web server solution stack package, consisting mainly of the Apache HTTP Server, MySQL database, and interpreters for scripts written in the PHP and Perl programming languages.
XAMPP is a very easy to install Apache Distribution for Linux, Solaris, Windows and Mac OS X. The package includes the Apache web server, MySQL, PHP, Perl, a FTP server and PhpMyAdmin.

It is also called XAMPP. You can download it for Windows or  Linux. You can download XAMPP/LAMPP for windows or Linux from here :

XAMPP for Windows : Click Here
XAMPP for Linux : Click Here
XAMPP download List for MAC OS X, Solaris : Click Here

Note : Phpmyadmin is an interface for Mysql database where you can easily write query, create, alter, delete tables/databases. Here you can also see the performance of database.

Installation :

In Linux :

After downloading simply type in the following commands:

  • Go to a Linux shell.
  • Extract the downloaded archive file to /opt:
  • Type  sudo tar xvfz xampp-linux-1.8.1.tar.gz -C  /opt 
  • Now the file will be extracted in opt/lampp directory.

Step 3: Start

  • To start XAMPP simply call this command:
      sudo /opt/lampp lampp start

  • You should now see something like this on your screen:
         
Now your lampp is Ready. Apache and MySQL  are running.
If you get any error messages please take a look at the Linux FAQ.

Step 4: Test

OK, that was easy but how can you check that everything really works? Just type in the following URL at your favourite web browser:  
http://localhost



Here you go Xampp/Lampp is installed now on your Machine. :)

Click Here for Yii Installation

Thursday, October 4, 2012

This blog is specially designed for the Yii Framework  tutorial. Here I will start the tutorial from very basics of Yii Framework like Hello World :). And then step by step I will increase the level. I will also describe the problems which I use to get during development so that a very new developer can also understand the problems.

On Yii framework there are a lot of tutorials are present but I could not found any website which is explaining from basic. So this blog will also be helpful for a novice developer in this field. I would like to get comment and suggestion. 

Thank You