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


OR

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?

type

/etc/init.d/memcached status

/etc/init.d/memcached start

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

Now run the memcached script on server:

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

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

        $cache->connect("127.0.0.1");
        //addServer("127.0.0.1",11211);
        $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";
    }
    else
    {
            $tVar = $cache->get($user_key);
        echo '<PRE>';
        print_r($tVar);
        echo "Out";
    }
        ?>
    </body>
</html>


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.

Cheers!

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.

e.g.,

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

Cheers!

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.

therefore,

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

Cheers!

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',

Cheers!

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()
    {
        $.ajax({       
               data: { fname: 'ashwani kumar' },             
              type: 'POST',
                  url: 'ajax.php',
                success: function(data) {
                    alert('success');
                    $('#content').html(data);           
                 },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                     //alert(XMLHttpRequest.status);
                    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:

if(!isset($_SESSION['name']))
{
    header("HTTP/1.0 500 Not Found");
    exit;
}


Cheers!

Monday 21 June 2010

How to post form using ajax in jquery?

 $.post(url, $("#"+$formname).serialize(),
    function(data){
      $('#content').html(data);
    });

Cheers!

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 ./

Cheers!

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

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

Cheers!

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



Cheers!

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'),
  );

http_build_query($params);

Second Method:

$this->form = new ContactForm();
http_build_query($this->form->getValues());


Cheers!

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.

Cheers!

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.

Thanks

Cheers!

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');

Cheers!

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();
 
 
Cheers! 

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...
$this->getUser()->getAttributeHolder()->remove('nickname');

Cheers!

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:192.168.29.231  Bcast:192.168.29.255  Mask:255.255.255.192
          inet6 addr: fe80::225:64ff:feba:672d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          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)
          Interrupt:16

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          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.

Thanks

Cheers!

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.

Cheers!

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

Cheers!