Tuesday, 29 June 2010

How to Install MEMCACHED on ubuntu?

first of all write the following command on command line:

sudo apt-get install memcached
now go to php.ini file and enable memcache.so


following command automatically append php.ini file and write memcache.so

sudo apt-get install php5-memcache memcached

now check memcached is running or not?


/etc/init.d/memcached status

/etc/init.d/memcached start

To check wether 11211 port is enable or not with
telnet 127.0.01 11211

Now run the memcached script on server:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        // put your code here
        $cache = new Memcache();

        $user_key = 12345;

    /** Look in cache, if not found, set object (misses null) **/
    if (!$user = $cache->get($user_key)) {
       * Set object with expire of 1 hour and no compression
      $value = array(34,56,34,23,23,124,65,767,34,76576,99);
      $cache->set($user_key, $value, NULL, 6000);
      $user = $value;
      echo "In";
            $tVar = $cache->get($user_key);
        echo '<PRE>';
        echo "Out";

This script will first time enter in if condition and second time in else condition.... if it does then your memcached is working fine else there is some error.


Friday, 25 June 2010

How to login on other server using command line?

Write down the following in the terminal:

$ ssh <username>@<IP Address>
and then press enter. It will be asked to enter password.
give password and you are done.


$ ssh root@
it will ask password. give password and done.


what are 777 means in sense of permissions?

Whenever we give permission to the folder or anything, we usually write 777.
Here are three 777.
First seven means permission is giving to User(Owner)
Second seven means permission is giving to Group
Third seven means permission is giving to Others

so 777 means UGO

now comes to each 7. what the means of 7?

each 7 consist read, write or execute permission.


read(r)      : 4
write(w)     : 2
execute(x) : 1

Suppose, if we want to give read, write and execute permission then

read + write + execute (rwx) => 4 +2 + 1 => 7
read + write (rw) => 4 + 2 => 6
read + execute (rx) => 4 + 1 => 5
write + execute (wx) => 2+1 => 3


What are the http/1.1 status code?

   '100' => 'Continue',
    '101' => 'Switching Protocols',
    '200' => 'OK',
    '201' => 'Created',
    '202' => 'Accepted',
    '203' => 'Non-Authoritative Information',
    '204' => 'No Content',
    '205' => 'Reset Content',
    '206' => 'Partial Content',
    '300' => 'Multiple Choices',
    '301' => 'Moved Permanently',
    '302' => 'Found',
    '303' => 'See Other',
    '304' => 'Not Modified',
    '305' => 'Use Proxy',
    '306' => '(Unused)',
    '307' => 'Temporary Redirect',
    '400' => 'Bad Request',
    '401' => 'Unauthorized',
    '402' => 'Payment Required',
    '403' => 'Forbidden',
    '404' => 'Not Found',
    '405' => 'Method Not Allowed',
    '406' => 'Not Acceptable',
    '407' => 'Proxy Authentication Required',
    '408' => 'Request Timeout',
    '409' => 'Conflict',
    '410' => 'Gone',
    '411' => 'Length Required',
    '412' => 'Precondition Failed',
    '413' => 'Request Entity Too Large',
    '414' => 'Request-URI Too Long',
    '415' => 'Unsupported Media Type',
    '416' => 'Requested Range Not Satisfiable',
    '417' => 'Expectation Failed',
    '500' => 'Internal Server Error',
    '501' => 'Not Implemented',
    '502' => 'Bad Gateway',
    '503' => 'Service Unavailable',
    '504' => 'Gateway Timeout',
    '505' => 'HTTP Version Not Supported',


How to check session is exit or not using ajax call with jquery?

Hey fox please do the below mentioned code to check it out whether session is exist or not via ajax call:

Write down the following code while call ajax;

function callAjax()
               data: { fname: 'ashwani kumar' },             
              type: 'POST',
                  url: 'ajax.php',
                success: function(data) {
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    if (XMLHttpRequest.status === 500) {
                      location.href = 'index.php';

IN ajax.php file on top of the page write down the following code in your script:

    header("HTTP/1.0 500 Not Found");


Monday, 21 June 2010

How to post form using ajax in jquery?

 $.post(url, $("#"+$formname).serialize(),


Thursday, 17 June 2010

How to download/checkout code from svn?

go to the directory where you wanna download code and then write the following in terminal:

$ svn co codepath ./


How to import sql file using linux?

First go to the directory where your sql file is saved and then type the following: 

$ mysql -u root -p payforme < payforme_dev.sql

root is the username of mysql
payforme is the database name
payforme_dev.sql is the sql file.


Tuesday, 15 June 2010

How to start/stop/restart apache on ubuntu?

## start apache on ubuntu...
$ sudo /etc/init.d/apache2 start

## stop apache on ubuntu...
$ sudo /etc/init.d/apache2 stop

## restart apache on ubuntu...
$ sudo /etc/init.d/apache2 restart


How to install curl on ubuntu?

## install curl in php on ubuntu...

$ sudo apt-get install php5-curl

Friday, 11 June 2010

How to create query parameter in symfony?

There are two ways to make query parameters:

First Method:

$params = array(
    'name'    => $request->getParameter('name'),
    'email'   => $request->getParameter('email'),
    'message' => $request->getParameter('message'),


Second Method:

$this->form = new ContactForm();


Create Module from command line in symfony?

First go to the your project folder and then type 

$ php symfony generate:module frontend contact

it will generate all the folder related to contact module.


How to clear Simfony Chache?

First go to the project foleder and then type the following command on command line i.e., Terminal

$ php symfoy cc

and then press enter.

This will clear all the cache of your project.



How to GET, POST or REQUEST parameters in symfony?

suppose, randomToken variable coming from the last page either GET or POST.

Using the following command, you can fetch that variable:

$rondomToken = $this->getRequestParameter('randomToken');


How to set Cookie in symfony?

// cookie getter
$string = $this->getRequest()->getCookie('mycookie');
// cookie setter
$this->getResponse()->setCookie('mycookie', $value);
// cookie setter with options
$this->getResponse()->setCookie('mycookie', $value, $expire, $path, $domain, $secure);
If you want to manipulate cookies outside of an action, you will need to access the Request and Answer objects without shortcut: 
$request  = sfContext::getInstance()->getRequest();
$response = sfContext::getInstance()->getResponse();

How to set, get and remove session variables in symfony?

## Create Session Variables...
$this->getUser()->setAttribute('nickname', 'ashwani');

## Retrieve Session Variables...
$this->nickname = $this->getUser()->getAttribute('nickname');
## Check if session is exist return 1 else blank value...
$hasNickname = $this->getUser()->hasAttribute('nickname');

## Remove Session Variable...


Wednesday, 9 June 2010

How to see IP Address of a system in Linux?

Write following command on command line:

$ /sbin/ifconfig/

As soon as you enter, you will se following on the screen:

eth0      Link encap:Ethernet  HWaddr 00:25:64:ba:67:2d 
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::225:64ff:feba:672d/64 Scope:Link
          RX packets:51598 errors:0 dropped:0 overruns:0 frame:0
          TX packets:27730 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:15121530 (14.4 MB)  TX bytes:6643763 (6.3 MB)

lo        Link encap:Local Loopback 
          inet addr:  Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:12269 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12269 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:13829812 (13.1 MB)  TX bytes:13829812 (13.1 MB)

The bold text is your IP Address.



What are the upload credentials for php.ini ?

Following are the hierarchy for uploading a file:

memory limit > upload post size > upload max filesize

by default in php.ini, it is 16M > 4M> 2M.


How to access LAMP configurations from putty?

Type the following command on command line:

For edit apache configuration file use the follwoing :
$ gedit /etc/apache2/httpd.conf
$ gedit /etc/apache2/apache2.conf

For edit php.ini file, use the follwoing :
$ gedit /etc/php5/apache2/php.ini