#php

Difference between Static Method and Dynamic Method

The easiest way to understand is we should start from looking at our code to know how to we used Static Method and Dynamic Method,

With Static Method:

With Dynamic Method:

So you will easily to recognize that Static Methods are usually used in static library. For example, you create a class to handle string as cuting string, uppercase … And based on the script above,  we see that Dynamic Method just is used after creating a instance of object.

You do not need to concern to performance when choose Static or Dynamic Method, just focus to software design. You can use Static Method when you need and choose Dynamic Method when you need instantiate your class.

Install MongoDB and Mongo PHP in Ubuntu

I am using Ubuntu Server 14.04 OS for my working enviroment. All steps below is way I implemented successfully on my machine. So now, I will show you how to install MongoDB and Mongo PHP driver.

530df3ee-2908-11e4-beda-12313d275d6d-medium

Firstly, install MongoDB. You can see it is so simple and one and only one command.

To make sure that MongDB is running, you can use command below

To install Mongo PHP Driver, you use the command below.

The command above use Pecl, so if you machine have not installed it yet. You can install easily by the command below

And now, you have to enable Mongo PHP extension by way add “extension=mongo.so” to php.ini file or use the commands below

Almost done, just need to check that your job is done or not.

And writing a php script to create document, collection and insert data to mongodb.

If success, the output will be same as the below

 

Install PHP Redis in Ubuntu

Redis is good solution to improve the performance of your system. You can use Redis as cache system or nosql DB.  I think that is is easy to use it but not easy to think how and where.

Step 1,  install redis, phpize

Test redis:

Install phpize

Step 2,  download phpredis source code from git

If you have not installed git yet, you can use this command line:

Step 3, compile and install phpredis,

Step 3, enable phpredis extension

Step 4, test

Writing a php script to test

Doing some quick and dirty benchmark

 

Good luck,

PHP LinkedIn Oauth2 Example

The source code below implements 3 steps to get user information from LinkedIn.

Step 1: Start authorization process

Step 2: Get access token

Step 3: Fetch user information (user name, first name, last name …)