Sunday, October 16, 2011

PHP jQuery AJAX Javascript Long Polling

Background

"Long polling" is the name used to describe a technique which:
  • An AJAX request is made (utilizing a javascript framework such as jQuery)
  • The server waits for the data requested to be available, loops, and sleeps (your server-side PHP script)
  • This loop repeats after data is returned to the client and processed (usually in your AJAX request's onComplete callback function)
This essentially simulates a continuous real-time stream from the client to the server. It can be more efficient than a regular polling technique because of the reduction in HTTP requests. You're not asking over and over and over again for new data - you ask once and wait for an answer. In most cases this reduces the latency in which data becomes available to your application.
There are a variety of use cases in which this technique can be handy. At the top of the list are real-time web-based chat applications. Each client executes a long polling loop for chat and user events (sign on/sign off/new message). Meebo is perhaps the greatest example of this.
It's important to note some of the server side technical limitations of long polling. Because connections remain open for considerably longer time than a typical HTTP request/response cycle you want your web server to be able to handle a large number of simultaneous connections. Apache isn't the best candidate for this type of situation. nginx and lighttpd are two lightweight web servers built from the ground up to handle a high volume of simultaneous connections. Both support the FastCGI interface and as such can be configured to support PHP. Again, Meebo uses lighttpd.
For similar reasons - it's also a good idea to choose a different sub-domain to handle long polling traffic. Because of client side browser limitations you don't want long polling connections interfering with regular HTTP traffic delivering page and media resources for your application.

Implementation

jQuery makes implementation a breeze.


var lpOnComplete = function(response) {
    alert(response);
    // do more processing
    lpStart();
};
 
var lpStart = function() {
    $.post('/path/to/script', {}, lpOnComplete, 'json');
};
 
$(document).ready(lpStart);
 
 
Straightforward. When the document is ready the loop begins. Each iteration the returned data is processed and the loop is restarted.
On the server side - just like we discussed earlier:


$time = time();
while((time() - $time) < 30) {
    // query memcache, database, etc. for new data
    $data = $datasource->getLatest();
 
    // if we have new data return it
    if(!empty($data)) {
        echo json_encode($data);
        break;
    }
 
    usleep(25000);
}
 
Actually, a couple points of interest here. We don't actually loop infinitely server side. You may have noticed the logic for the while loop - if we've executed for more than 30 seconds we discontinue the loop and return nothing. This nearly eliminates the possibility of substantial memory leaks. Also, if we didn't put a cap on execution time we would need to print a "space" character and flush output buffers every iteration of the loop to keep PHP abreast to the status of this process/connection. Without output being sent PHP cannot determine if the connection was lost via connection_status() or connection_aborted(). As a result this could lead to a situation where there are an increasing number of "ghost" processes eating up server resources. Not good!
That pretty much sums it up! Not that difficult, right?

Friday, June 24, 2011

How to install LAMP + Zend Ubuntu 11.04

 It's super easy to install LAMP server in Ubuntu 11.04, just need to run the follow command, sudo apt-get install lamp-server^ You may ask to set up root password for mysql during the installation, other than that, everything is automatically. To restart apache, run the following command, sudo /etc/init.d/apache2 restart OK, install Zend is also easy, sudo apt-get install zend-framework After that you have to make sure zend library path is included. Go to php.ini (@/etc/php5/apache2/), edit the following line, ; UNIX: "/path1:/path2" include_path = ".:/usr/share/php:/usr/share/php/libzend-framework-php" I also found, after added include_path in the php.ini, the Zend library is still not found if I run the php script in the command line. Not sure why, but the solution I found is uncomment the line at /etc/php5/conf.d/zend-framework.ini, [Zend] include_path=${include_path} ":/usr/share/php/libzend-framework-php" Happy ubuntu!

Thursday, May 19, 2011

Tuesday, May 10, 2011

How to install opencv2.2.0 on ubuntu 10.10

This is how to build and install OpenCV 2.2 on Ubuntu 10.10.

First, install the dependencies from the repositories:

sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev
Download the source code:
wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.2/OpenCV-2.2.0.tar.bz2
Extract, create the build directory:
tar xfv OpenCV-2.2.0.tar.bz2
rm OpenCV-2.2.0.tar.bz2
cd OpenCV-2.2.0
mkdir opencv.build
cd opencv.build
Configure, make and install:
cmake ..
make
sudo make install
To configure the library, edit the following file (might be empty):
sudo gedit /etc/ld.so.conf.d/opencv.conf
and add the line
/usr/local/lib
Then run:
sudo ldconfig
Finally, edit the file:
sudo gedit /etc/bash.bashrc
and add the following lines at the end:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

Mysql Command

This is a list of handy MySQL commands that I use time and time again. At the bottom are statements, clauses, and functions you can use in MySQL. Below that are PHP and Perl API functions you can use to interface with MySQL. To use those you will need to build PHP with MySQL functionality. To use MySQL with Perl you will need to use the Perl modules DBI and DBD::mysql.
Below when you see # it means from the unix shell. When you see mysql> it means from a MySQL prompt after logging into MySQL.

To login (from unix shell) use -h only if needed.

# [mysql dir]/bin/mysql -h hostname -u root -p

Create a database on the sql server.

mysql> create database [databasename];

List all databases on the sql server.

mysql> show databases;

Switch to a database.

mysql> use [db name];

To see all the tables in the db.

mysql> show tables;

To see database's field formats.

mysql> describe [table name];

To delete a db.

mysql> drop database [database name];

To delete a table.

mysql> drop table [table name];

Show all data in a table.

mysql> SELECT * FROM [table name];

Returns the columns and column information pertaining to the designated table.

mysql> show columns from [table name];

Show certain selected rows with the value "whatever".

mysql> SELECT * FROM [table name] WHERE [field name] = "whatever";

Show all records containing the name "Bob" AND the phone number '3444444'.

mysql> SELECT * FROM [table name] WHERE name = "Bob" AND phone_number = '3444444';

Show all records not containing the name "Bob" AND the phone number '3444444' order by the phone_number field.

mysql> SELECT * FROM [table name] WHERE name != "Bob" AND phone_number = '3444444' order by phone_number;

Show all records starting with the letters 'bob' AND the phone number '3444444'.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444';

Show all records starting with the letters 'bob' AND the phone number '3444444' limit to records 1 through 5.

mysql> SELECT * FROM [table name] WHERE name like "Bob%" AND phone_number = '3444444' limit 1,5;

Use a regular expression to find records. Use "REGEXP BINARY" to force case-sensitivity. This finds any record beginning with a.

mysql> SELECT * FROM [table name] WHERE rec RLIKE "^a";

Show unique records.

mysql> SELECT DISTINCT [column name] FROM [table name];

Show selected records sorted in an ascending (asc) or descending (desc).

mysql> SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;

Return number of rows.

mysql> SELECT COUNT(*) FROM [table name];

Sum column.

mysql> SELECT SUM(*) FROM [table name];

Join tables on common columns.

mysql> select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id;

Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO user (Host,User,Password) VALUES('%','username',PASSWORD('password'));
mysql> flush privileges;

Change a users password from unix shell.

# [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password 'new-password'

Change a users password from MySQL prompt. Login as root. Set the password. Update privs.

# mysql -u root -p
mysql> SET PASSWORD FOR 'user'@'hostname' = PASSWORD('passwordhere');
mysql> flush privileges;

Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server.

# /etc/init.d/mysql stop
# mysqld_safe --skip-grant-tables &
# mysql -u root
mysql> use mysql;
mysql> update user set password=PASSWORD("newrootpassword") where User='root';
mysql> flush privileges;
mysql> quit
# /etc/init.d/mysql stop
# /etc/init.d/mysql start

Set a root password if there is on root password.

# mysqladmin -u root password newpassword

Update a root password.

# mysqladmin -u root -p oldpassword newpassword

Allow the user "bob" to connect to the server from localhost using the password "passwd". Login as root. Switch to the MySQL db. Give privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> grant usage on *.* to bob@localhost identified by 'passwd';
mysql> flush privileges;

Give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs.

# mysql -u root -p
mysql> use mysql;
mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES ('%','databasename','username','Y','Y','Y','Y','Y','N');
mysql> flush privileges;

or

mysql> grant all privileges on databasename.* to username@localhost;
mysql> flush privileges;

To update info already in a table.

mysql> UPDATE [table name] SET Select_priv = 'Y',Insert_priv = 'Y',Update_priv = 'Y' where [field name] = 'user';

Delete a row(s) from a table.

mysql> DELETE from [table name] where [field name] = 'whatever';

Update database permissions/privilages.

mysql> flush privileges;

Delete a column.

mysql> alter table [table name] drop column [column name];

Add a new column to db.

mysql> alter table [table name] add column [new column name] varchar (20);

Change column name.

mysql> alter table [table name] change [old column name] [new column name] varchar (50);

Make a unique column so you get no dupes.

mysql> alter table [table name] add unique ([column name]);

Make a column bigger.

mysql> alter table [table name] modify [column name] VARCHAR(3);

Delete unique from table.

mysql> alter table [table name] drop index [colmn name];

Load a CSV file into a table.

mysql> LOAD DATA INFILE '/tmp/filename.csv' replace INTO TABLE [table name] FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (field1,field2,field3);

Dump all databases for backup. Backup file is sql commands to recreate all db's.

# [mysql dir]/bin/mysqldump -u root -ppassword --opt >/tmp/alldatabases.sql

Dump one database for backup.

# [mysql dir]/bin/mysqldump -u username -ppassword --databases databasename >/tmp/databasename.sql

Dump a table from a database.

# [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename > /tmp/databasename.tablename.sql

Restore database (or database table) from backup.

# [mysql dir]/bin/mysql -u username -ppassword databasename < /tmp/databasename.sql

Create Table Example 1.

mysql> CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255));

Create Table Example 2.

mysql> create table [table name] (personid int(50) not null auto_increment primary key,firstname varchar(35),middlename varchar(50),lastnamevarchar(50) default 'bato');

Thursday, April 7, 2011

How to recover / change the root password on RedHat Linux based systems

When you lost your root password in a RedHat Linux Based systems you should first have access to the console, (the machine itself).
Power on, or reboot as needed.
and as soon as you get this screen (or similar depending your system and configurations)
screenshot 0
Now you should press 'e' and you will get this screen.
Screenshot 1
Select the image you would like to boot, and press 'e' again, and as soon as you get the nex screen
Screenshot 2
Insert an space and the number one '1' as shown in the image.
After that press ENTER and 'b' and ENTER again.


Screenshot 3Your will now have your System booted as a single user and you will have no need to enter a password.
Now you can change the password like this
#passwd
#reboot
And you will have againg your system working.
Here you can see the las two images, showing this.

ScreenShot 4ScreenShot 4

Wednesday, April 6, 2011

How to reset Mysql password

service mysqld stop or /etc/init.d/mysqld stop

wait until MySQL shuts down. Then run

mysqld_safe --skip-grant-tables &

then you will be able to login as root with no password.

mysql -uroot mysql

In MySQL command line prompt issue the following command:

UPDATE user SET password=PASSWORD("abcd") WHERE user="root";
FLUSH PRIVILEGES;
EXIT

/etc/init.d/mysqld restart

Monday, February 14, 2011

How to fix undefined symbol: apr_strtoff +mod_flvx under apache

Add this code to the mod_flvx.c file:


#if APR_HAS_LARGE_FILES
#define APR_OFF_T_STRFN       strtoll
#else
#define APR_OFF_T_STRFN       strtol
#endif
/* A "safe" maximum bucket size, 1Gb */
#define MAX_BUCKET_SIZE (0x40000000)
APU_DECLARE(apr_bucket *) apr_brigade_insert_file(apr_bucket_brigade *bb,
                                                  apr_file_t *f,
                                                  apr_off_t start,
                                                  apr_off_t length,
                                                  apr_pool_t *p)
{
    apr_bucket *e;
    if (sizeof(apr_off_t) == sizeof(apr_size_t) || length < MAX_BUCKET_SIZE) {
        e = apr_bucket_file_create(f, start, (apr_size_t)length, p,
                                   bb->bucket_alloc);
    }
    else {
        /* Several buckets are needed. */
        e = apr_bucket_file_create(f, start, MAX_BUCKET_SIZE, p,
                                   bb->bucket_alloc);
        while (length > MAX_BUCKET_SIZE) {
            apr_bucket *ce;
            apr_bucket_copy(e, &ce);
            APR_BRIGADE_INSERT_TAIL(bb, ce);
            e->start += MAX_BUCKET_SIZE;
            length -= MAX_BUCKET_SIZE;
        }
        e->length = (apr_size_t)length; /* Resize just the last bucket */
    }
    APR_BRIGADE_INSERT_TAIL(bb, e);
    return e;

}
APR_DECLARE(apr_status_t) apr_strtoff(apr_off_t *offset, const char *nptr, char **endptr, int base)
{
 errno = 0;
 *offset = APR_OFF_T_STRFN(nptr, endptr, base);
 return APR_FROM_OS_ERROR(errno);
}

Wednesday, January 26, 2011

How to Handle multiple selection drop down list box

ou can read how drop down list boxes works for selecting one options out of many. You have also seen how the data of a pull down list box is handled inside a form. Here PHP is used to collect the selection of the form for further processing.

As you have seen in our processing script we collect the option selected by user by using appropriate GET or POST methods. Here is one example. Let us say the list box of colors we have used and the option selected by user is collected like this

$color=$_POST['color'];


or

$color=$_GET['color'];


Based on the form method ( GET or POST ) we can get or collect the option selected and store them in variable $color.

Same way let us see how we can get multiple selections from a drop down list box. Here is the demo of multiple selection pull down list box.

Here we get the selected values as array ( not as a single value ) , now this array we can loop through and display the elements. Here is the code to display the list box and then the collection of selected options.

 

Here is the code to handle the above script.
<form method=post action=''>
<select name='color[]' size=4 multiple>
<option value='blue'>Blue</option>
<option value='green'>Green</option>
<option value='red'>Red</option>
<option value='yellow'>Yelllow</option>
<option value='' selected>Select a Color </option>
<option value='white'>White</option>
</select>
<input type=submit></form>

///// collecting form data /////

@$color= $_POST['color'];
if( is_array($color)){
while (list ($key, $val) = each ($color)) {
echo "$val <br>";
}
}//else{echo "not array";}

Saturday, January 22, 2011

How to change column datatype in mysql


Mysql Alter Column Datatype is used to modify the table and change the datatype of field.
Understand with Example
The Tutorial illustrate an example from 'Mysql Alter Column  Datatype'. To understand this example we create a table 'employees' with empid as Primary Key.
Query to create table:
CREATE TABLE `employees` (               
            ->Empid int(10),  
            ->Empname varchar(60),    
             ->date date
            ->PRIMARY KEY(empid)  
           ->);
Query to insert data into Table named employees:
The Query insert into add the records or rows into the table 'employees'.
mysql>insert into employees values(01,'Girish','2008-12-22');
Query OK, 1 row affected (0.02 sec)
mysql>insert into employee1 values(02,'Komal','2008-12-23');
Query OK, 1 row affected (0.02 sec)
Query to view data of  Table named employees:
To view the detail of table 'employee1' we use select query that return the detail of records.
mysql> select * from employee;
Output:-
+-------+---------+------------+
| Empid | Empname | date       |
+-------+---------+------------+
|     1 | Girish  | 2008-12-22 |
|     2 | Komal   | 2008-12-23 |
+-------+---------+------------+
2 rows in set (0.00 sec)

Data type of Table named employees before altering column data type:
The describe employee describe the field name ,data type ,null ,key etc in table employees
+---------+-------------+------+-----+---------+----------------+
| Field   | Type        | Null | Key | Default | Extra          |
+---------+-------------+------+-----+---------+----------------+
| empid   | int(11)     | NO   | PRI | NULL    | auto_increment |
| Empname | varchar(60) | NO   |     |         |                |
| date    | date        | YES  |     | NULL    |                |
+---------+-------------+------+-----+---------+----------------+
3 rows in set (0.02 sec)
Query to alter column data type of the Table named employees:
The Alter Query redefine the table 'employee' and change the data type of column  'empid'.
mysql> alter table employees
    -> change empid empid varchar(100);
Query OK, 2 rows affected (0.13 sec)
Records: 2  Duplicates: 0  Warnings: 0
Data type of Table named employees after altering column data type:
The describe employee describe the field name ,data type ,null ,key etc in table employees.
mysql> describe employees;
+---------+--------------+------+-----+---------+-------+
| Field   | Type         | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| empid   | varchar(100) | NO   | PRI |         |       |
| empname | varchar(130) | YES  |     | NULL    |       |
| date    | date         | YES  |     | NULL    |       |
+---------+--------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

Thursday, January 20, 2011

How to add a column to an existing table with Mysql


To add a column calledemail to the contacts table created in Create a basic MySQL table with a datatype of VARCHAR(80), use the following SQL statement:
ALTER TABLE contacts ADD email VARCHAR(60);
This first statement will add the email column to the end of the table. To insert the new column after a specific column, such as name, use this statement:
ALTER TABLE contacts ADD email VARCHAR(60) AFTER name;
If you want the new column to be first, use this statement:
ALTER TABLE contacts ADD email VARCHAR(60) FIRST;

Wednesday, January 19, 2011

Ho to find the php.ini configurartion file

First create a php file and put this code :

<?php
echo  phpinfo() ;

?>

Second:
browse to the file ,for example howto-heaven.com/phpinfo.php

Finally search for Loaded Configuration File ,you will find the path of the file.

How to check php loaded modules

Just type this command :
php -m

Tuesday, January 11, 2011

How to fix "/usr/bin/ld: cannot find -lglut "

I was trying to istall MP4Box under centos but i get this error when i tried to execute the make lib command: /usr/bin/ld: cannot find -lglut

The solution is too simple ,just add a symbolic link to libglut : ln -s /usr/lib64/libglut.so.3 /usr/lib64/libglut.so

How shared libraries work

Shared libraries are a fundamental component for the efficient use of space and resources on a modern UNIX® system. The C library on a SUSE 9.1 system is made up of about 1.3 MB. A copy of that library for every program in /usr/bin (and I have 2,569!) would take up a couple of gigabytes of space.
Of course this number is inflated -- statically linked programs would incorporate only those parts of the library that they use. Nonetheless, the amount of space tied up by all those duplicate copies of printf() would give the system a very bloated feel.
Shared libraries can save memory, not just disk space. The kernel can keep a single copy of a shared library in memory, sharing it among multiple applications. So, not only do we only have one copy of printf() on the disk, we only have one in memory. That has a pretty noticeable effect on performance.
In this article, we'll review the underlying technology used for shared libraries and the way in which shared library versioning helps prevent the compatibility nightmares that naive shared library implementations have had in the past. First, a look at how shared libraries work.
The concept is easy enough to understand. You have a library; you share the library. But what actually happens when your program tries to call printf() -- the real way this works -- is a bit more complex.
It is a simpler process in a static linking system than in a dynamically linked system. In a static linked system, the generated code possesses a reference to a function. The linker replaces that reference with the actual address at which it had loaded the function, so that the resulting binary code has the right address in place. Then, when the code is run, it simply jumps to the relevant address. This is a simple task to administer because it lets you to link in only those objects that are actually referred to at some point in the program.
But most shared libraries are dynamically linked. That has several further implications. One is that you can't predict in advance at which address a function will really be when it's called! (There have also been statically linked shared library schemes, such as the one in BSD/OS, but they are beyond the scope of this article.)
The dynamic linker can do a fair amount of work for each function linked, so most linkers are lazy. They only actually finish that work when the function is called. With more than a thousand externally visible symbols in the C library and nearly three thousand more local ones, this idea could save a noticeable amount of time.
The magic trick here that makes it work is a chunk of data called a Procedure Linkage Table (PLT), a table in the program that lists every function that a program calls. When the program is started, the PLT contains code for each function to query the runtime linker for the address at which it has loaded a function. It then fills in that entry in the table and jumps there. As each function is called, its entry in the PLT is simplified into a direct jump to the loaded function.
However, it's important to notice that this still leaves an extra layer of indirection -- each function call is resolved through a jump into a table.
This means that the library you end up being linked to had better be compatible with the code that's calling it. With a statically linked executable, there is some guarantee that nothing will change on you. With dynamic linking, you don't have that guarantee.
What happens if a new version of the library comes out? Especially, what happens if the new version changes the calling sequence for a given function?
Version numbers to the rescue -- a shared library will have a version. When a program is linked against a library, it has the version number it's designed for stored in it. The dynamic linker can check for a matching version number. If the library has changed, the version number won't match, and the program won't be linked to the newer version of library.
One of the potential advantages of dynamic linking, however, is in fixing bugs. It'd be nice if you could fix a bug in the library and not have to recompile a thousand programs to take advantage of that fix. So sometimes, you want to link to a newer version.
Unfortunately, that creates some cases where you want to link to the newer version and some cases where you'd rather stick with an older version. There is a solution, though -- two kinds of version numbers:
  • A major number indicates a potential incompatibility between library versions.
  • A minor number indicates only bug fixes.
So under most circumstances, it is safe to load a library with the same major number and a higher minor number; consider it an unsafe practice to load a library with a higher major number.
To prevent users (and programmers) from needing to track library numbers and updates, the system comes with a large number of symbolic links. In general, the pattern is that
libexample.so
will be a link to
libexample.so.N
in which N is the highest major version number found on the system.
For every major version number supported,
libexample.so.N
will be a link in turn to
libexample.so.N.M
in which M is the largest minor version number.
Thus, if you specify -lexample to the linker, it looks for libexample.so which is a symbolic link to a symbolic link to the most recent version. On the other hand, when an existing program is loaded, it will try to load libexample.so.N in which N is the version to which it was originally linked. Everyone wins!
To debug problems with shared libraries, it's useful to know a little more about how they're compiled.
In a traditional static library, the code generated is usually bound together into a library file with a name ending in .a and then it's passed to the linker. In a dynamic library, the library file's name generally ends in .so. The file structures are somewhat different.
A normal static library is in a format created by the ar utility, which is basically a very simple-minded archive program, similar to tar but simpler. In contrast, shared libraries are generally stored in more complicated file formats.
On modern Linux systems, this generally means the ELF binary format (Executable and Linkable Format). In ELF, each file is made up of one ELF header followed by zero or some segments and zero or some sections. The segments contain information necessary for runtime execution of the file, while sections contain important data for linking and relocation. Each byte in the entire file is taken by no more than one section at a time, but there can be orphan bytes that are not covered by a section. Normally in a UNIX executable, one or more sections are enclosed in one segment.
The ELF format has specifications for applications and libraries. The library format is a lot more complicated than just a simple archive of object modules, though.
The linker sorts through references to symbols, making notes about in which libraries they were found. Symbols from static libraries are added to the final executable; symbols from shared libraries are put into the PLT, and references to the PLT are created. Once those tasks are done, the resulting executable has a list of symbols it plans to look up from libraries it will load at runtime.
At runtime, the application loads the dynamic linker. In fact, the dynamic linker itself uses the same kind of versioning as the shared libraries. On SUSE Linux 9.1, for instance, the file /lib/ld-linux.so.2 is a symbolic link to /lib/ld-linux.so.2.3.3. On the other hand, a program looking for /lib/ld-linux.so.1 won't try to use the new version.
The dynamic linker then gets to do all the fun work. It looks to see which libraries (and which versions) a program was originally linked to and then loads them. Loading a library consists of:
  • Finding it (and it may be in any of several directories on a system)
  • Mapping it into the program's address space
  • Allocating blocks of zero-filled memory the library may need
  • Attaching the library's symbol table
Debugging this process can be difficult. There are a few kinds of problems you can encounter. For example, if the dynamic linker can't find a given library, it will abort loading the program. If it finds all the libraries it wants but can't find a symbol, it can abort for that too (but it may not act until the actual attempt to reference that symbol occurs) -- this is rare case though because normally, if the symbol isn't there, it will be noticed during the initial link.
When linking a program, you can specify additional paths to search at runtime. In gcc the syntax is -Wl,-R/path. If the program is already linked, you can also change this behavior by setting the environment variable LD_LIBRARY_PATH. Usually this is needed only if your application wants to search paths that aren't part of the system-wide default, a rare case for most Linux systems. In theory, the Mozilla people could have distributed a binary compiled with that path set, but they preferred to distribute a wrapper script that sets the library path appropriately before launching the executable.
Setting the library path can provide a workaround in the rare case where two applications require incompatible versions of a library. A wrapper script can be used to have one application search in a directory using the special version of the library it requires. Hardly an elegant solution, but in some cases it's the best you can do.
If you have a compelling reason to add a path to many programs, you can also change the system's default search path. The dynamic linker is controlled through /etc/ld.so.conf, which contains a list of directories to search by default. Any paths specified in LD_LIBRARY_PATH will be searched before the paths listed in ld.so.conf, so users can override these settings.
Most users have no reason to change the system default library search paths; generally the environment variable is a better match for likely reasons to change the search path, such as linking with libraries in a toolkit or testing programs against a newer version of a library.
One useful tool for debugging shared library problems is ldd. The name derives from list dynamic dependencies. This program looks at a given executable or shared library and figures out what shared libraries it needs to load and which versions would be used. The output looks like this:

Listing 1. Dependencies of /bin/sh
$ ldd /bin/sh
        linux-gate.so.1 =>  (0xffffe000)
        libreadline.so.4 => /lib/libreadline.so.4 (0x40036000)
        libhistory.so.4 => /lib/libhistory.so.4 (0x40062000)
        libncurses.so.5 => /lib/libncurses.so.5 (0x40069000)
        libdl.so.2 => /lib/libdl.so.2 (0x400af000)
        libc.so.6 => /lib/tls/libc.so.6 (0x400b2000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

It can be a little surprising to find out how many libraries a "simple" program uses. It's probably the case that libhistory is the one calling for libncurses. To find out, we can just run another ldd command:

Listing 2. Dependencies of libhistory
$ ldd /lib/libhistory.so.4
        linux-gate.so.1 =>  (0xffffe000)
        libncurses.so.5 => /lib/libncurses.so.5 (0x40026000)
        libc.so.6 => /lib/tls/libc.so.6 (0x4006b000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)

In some cases, an application may need extra library paths specified. For instance, the first few lines of an attempt to run lddon the Mozilla binary came out like this:

Listing 3. Result of ldd for items not in search path
$ ldd /opt/mozilla/lib/mozilla-bin
  linux-gate.so.1 =>  (0xffffe000)
  libmozjs.so => not found
  libplds4.so => not found
  libplc4.so => not found
  libnspr4.so => not found
  libpthread.so.0 => /lib/tls/libpthread.so.0 (0x40037000)

Why aren't these libraries found? Because they're not in the usual search path for libraries. In fact, they're found in/opt/mozilla/lib, so one solution would be to add that directory to LD_LIBRARY_PATH.
Another option is to set the path to . and run ldd from that directory, although this is a little more dangerous -- putting the current directory in your library path is just as potentially treacherous as putting it in your executable path.
In this case, it's pretty clear that adding the directory these are in to the system-wide search path would be a bad idea. Nothing but Mozilla needs these libraries.
And speaking of Mozilla, in case you were thinking that you'd never see more than a few lines of libraries, here's a somewhat more typical large application. Now you can see why Mozilla takes so long to launch!

Listing 4. Dependencies of mozilla-bin
linux-gate.so.1 =>  (0xffffe000)
libmozjs.so => ./libmozjs.so (0x40018000)
libplds4.so => ./libplds4.so (0x40099000)
libplc4.so => ./libplc4.so (0x4009d000)
libnspr4.so => ./libnspr4.so (0x400a2000)
libpthread.so.0 => /lib/tls/libpthread.so.0 (0x400f5000)
libdl.so.2 => /lib/libdl.so.2 (0x40105000)
libgtk-x11-2.0.so.0 => /opt/gnome/lib/libgtk-x11-2.0.so.0 (0x40108000)
libgdk-x11-2.0.so.0 => /opt/gnome/lib/libgdk-x11-2.0.so.0 (0x40358000)
libatk-1.0.so.0 => /opt/gnome/lib/libatk-1.0.so.0 (0x403c5000)
libgdk_pixbuf-2.0.so.0 => /opt/gnome/lib/libgdk_pixbuf-2.0.so.0 (0x403df000)
libpangoxft-1.0.so.0 => /opt/gnome/lib/libpangoxft-1.0.so.0 (0x403f1000)
libpangox-1.0.so.0 => /opt/gnome/lib/libpangox-1.0.so.0 (0x40412000)
libpango-1.0.so.0 => /opt/gnome/lib/libpango-1.0.so.0 (0x4041f000)
libgobject-2.0.so.0 => /opt/gnome/lib/libgobject-2.0.so.0 (0x40451000)
libgmodule-2.0.so.0 => /opt/gnome/lib/libgmodule-2.0.so.0 (0x40487000)
libglib-2.0.so.0 => /opt/gnome/lib/libglib-2.0.so.0 (0x4048b000)
libm.so.6 => /lib/tls/libm.so.6 (0x404f7000)
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x40519000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x405d5000)
libc.so.6 => /lib/tls/libc.so.6 (0x405dd000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x406f3000)
libXrandr.so.2 => /usr/X11R6/lib/libXrandr.so.2 (0x407ef000)
libXi.so.6 => /usr/X11R6/lib/libXi.so.6 (0x407f3000)
libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x407fb000)
libXft.so.2 => /usr/X11R6/lib/libXft.so.2 (0x4080a000)
libXrender.so.1 => /usr/X11R6/lib/libXrender.so.1 (0x4081e000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x40826000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x40850000)
libexpat.so.0 => /usr/lib/libexpat.so.0 (0x408b9000)

Users interested in learning more about dynamic linking on Linux have a broad field of options. The GNU compiler and linker tool chain documentation is excellent, although the guts of it are stored in the info format and not mentioned in the standard man pages.
The manual page for ld.so contains a fairly comprehensive list of variables that modify the behavior of the dynamic linker, as well as explanations of the different versions of the dynamic linker that have been used in the past.
Most Linux documentation assumes that all shared libraries are dynamically linked because on Linux systems, they generally are. The work needed to make statically linked shared libraries is substantial and most users don't gain any benefit from it, although the performance difference is noticeable on systems that support the feature.
If you're using a pre-packaged system off the shelf, you probably won't run into very many shared library versions -- the system probably just ships with the ones it was linked against. On the other hand, if you do a lot of updates and source builds, you can end up with many versions of a shared library since old versions get left around "just in case."
As always, if you want to know more, experiment. Remember that nearly everything on a system refers back to those same few shared libraries, so if you break one of the system's core shared libraries, you're going to get to play with some kind of system recovery tool.

How to install ffmpeg,mp4box,mplayer,mencoder,flvtool2,ffmpeg-php on centos

 This article describes installation of ffmpeg, flvtool2, mplayer, mencoder, MP4Box, ffmpeg-php and many other video conversion tools on a CentOS cpanel server.
1. Enable RPM Fusion yum repository
The CentOS rpm packages of ffmpeg, mplayer, mencoder and MP4Box are available on RPM Fusion YUM repository. RPM Fusion repo depends on packages from EPEL repo. So enable these repositories by installing following RPM packages:
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -Uvh http://download1.rpmfusion.org/free/el/updates/testing/5/i386/rpmfusion-free-release-5-0.1.noarch.rpm
rpm -Uvh http://download1.rpmfusion.org/nonfree/el/updates/testing/5/i386/rpmfusion-nonfree-release-5-0.1.noarch.rpm
Note: for following ‘yum‘ commands, use the switch  –exclude “*.i386″ on 64-bit systems so as to avoid installing both 64-bit and 32-bit packages. Of course, DO NOT use this switch on 32-bit systems :-) 
2. Install ffmpeg, mplayer and mencoder
Install these packages using following yum command:
yum install ffmpeg mplayer mencoder
This will also install various dependency packages like libtheora, libvorbis, libogg, lame, opencore-amr, x264, xvidcore etc
3. Install flvtool2
This rpm package is available on RPM Fusion repo. But it also requires ruby rpms. However, it is not recommend to install ruby rpms on a cpanel server. Cpanel has its own ruby installer script. So install ruby using following cpanel script
/scripts/installruby
Flvtool2 is available as a Ruby Gems package. Use following gem command to install flvtool2:
gem install flvtool2
4. Install MP4Box
MP4Box is provided by gpac package. Install gpac and its library packages:
yum install gpac gpac-libs
5. Install ffmpeg-php
Ffmpeg-php requires ffmpeg development package. Install this package using yum:
yum install ffmpeg-devel
Now download the latest ffmpeg-php package:
wget http://downloads.sourceforge.net/ffmpeg-php/ffmpeg-php-0.6.0.tbz2
Untar this package, build and install it with following commands:
tar xjf ffmpeg-php-0.6.0.tbz2
cd ffmpeg-php-0.6.0
phpize
./configure
make

make install
Common errors:
During ./configure step if you get an error like “ffmpeg headers not found. Make sure ffmpeg is compiled as shared libraries using the –enable-shared option”, then run following three commands and after that re-run ./configure:
mkdir /usr/local/include/ffmpeg/
cp -par /usr/include/ffmpeg/* /usr/local/include/ffmpeg/
find /usr/include/ffmpeg/ -name “*.h” -exec cp {} /usr/local/include/ffmpeg/ \;
The make install command will show PHP extensions path where ffmpeg PHP extension is installed:
root@server [~/ffmpeg-php-0.6.0]# make install
Installing shared extensions:     /usr/local/lib/php/extensions/no-debug-non-zts-20060613/
Now edit php.ini file (/usr/local/lib/php.ini) and make sure that value of extension_dir is set to PHP extension directory as given by above ‘make install’ command:
extension_dir = “/usr/local/lib/php/extensions/no-debug-non-zts-20060613″
Add following line just below extension_dir and this will enable ffmpeg PHP extension:
extension=”ffmpeg.so”
Restart Apache to make this change effective:
/scripts/restartsrv_httpd
You can verify the status of ffmpeg extension on a PHP info web page or from command line as given below:
root@server [~]# php -i | grep ffmpeg
ffmpeg
ffmpeg-php version => 0.6.0-svn
ffmpeg-php built on => Oct  5 2010 22:14:58
ffmpeg-php gd support  => enabled
ffmpeg libavcodec version => Lavc52.20.1
ffmpeg libavformat version => Lavf52.31.0
ffmpeg swscaler version => SwS0.7.1
ffmpeg.allow_persistent => 0 => 0
ffmpeg.show_warnings => 0 => 0
OLDPWD => /root/ffmpeg-php-0.6.0
_SERVER["OLDPWD"] => /root/ffmpeg-php-0.6.0
_ENV["OLDPWD"] => /root/ffmpeg-php-0.6.0
6. Installation paths
Following are the installation paths of tools that we installed:
ffmpeg -> /usr/bin/ffmpeg
mplayer -> /usr/bin/mplayer
mencoder -> /usr/bin/mencoder
flvtool2 -> /usr/bin/flvtool2
MP4Box -> /usr/bin/MP4Box
Thats all!