What is the advantge and disadvantage of mysql_connect() and mysql_pconnect() ?

April 16th, 2009 No comments

mysql_pconnect() will maintain a persistent connection to the database. Whenever your script calls the connect to database function, it first searches already existing connections to the database and if exists it will use the same connection to connect to the database, if not it will open a new connection to the database. ie. Connection is Persistent

where as mysql_connect() function will establish a new connection whenever a connection to database needed, and after executing the script, this function disconnects the connection. ie. connection is not a persistent one.

mysql_pconnect() function is used where your site has a Heavy Traffic and where as mysql_connect() function is used when there is moderate/less traffic to your site.

Regard’s

Alex P

System Administrator.

How to update/install latest RoundCube on cPanel

April 14th, 2009 4 comments

Update/install latest RoundCube on cPanel

First you will have to uninstall/remove exiting RoundCube files/folder/database on your server,

  • Uninstall/remove exiting RoundCube
cd /usr/local/cpanel/base
rm -rf roundcube*
mysql -e 'drop database roundcube';
/scripts/upcp

Now follow the following steps to  update/install latest roundcube  version ,we need to get Roundcube before we can use it. The easiest way to get it is to visit http://www.roundcube.net and click on “Downloads” or just go to http://roundcube.net/downloads. Wait for it to download and then unzip (using WinZip or ZipGenius or tar -xzf roundcubemail-0.1.tar.gz) in the current directory.

  • update/install latest roundcube
cd /usr/local/cpanel/base
wget -O roundcube.tar.gz http://nchc.dl.sourceforge.net/sourceforge/
roundcubemail/roundcubemail-0.2.1.tar.gz
rm -rf roundcube.tar.gz
mv -f roundcubemail-0.2.1/ roundcube
cd roundcube
chmod -R 777 temp
chmod -R 777 logs
  • Database Configuration

Create the database, database user and install the intial sql file. The following commands will do this for you.

mysql -e "CREATE DATABASE roundcube;"
mysql -e "GRANT ALL PRIVILEGES ON roundcube.* TO roundcube@localhost IDENTIFIED BY
'DATABASEPASSWORD';"
mysql -e "FLUSH PRIVILEGES;"
mysql -e "use roundcube; source SQL/mysql.initial.sql;"

You will have to replace the roundcube password with ‘DATABASEPASSWORD’ field.

  • Configuring RoundCube
cd config
mv db.inc.php.dist db.inc.php
mv main.inc.php.dist main.inc.php

then open database configruation file  db.inc.php in your favroite editor like vi or pico or nano
vi db.inc.php
Find following line

$rcmail_config['db_dsnw'] = 'mysql://roundcube:pass@localhost/roundcubemail';

Replace it with

$rcmail_config['db_dsnw'] = 'mysql://roundcube:DATABASEPASSWORD@localhost/roundcube';

Now Open main.inc.php

vi main.inc.php

Find

$rcmail_config['default_host'] = '';

Replace with

$rcmail_config['default_host'] = 'localhost';

Last steps , restart the mysql, cpanel services on your server. That’s it ,Have fun with your new Roundcube installation!!

Regards

AlexP

How to install memcache on linux server?

April 12th, 2009 No comments

memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load.

memcached is meant to work in concert with something like the MySQL query cache, not replace it. The two implementations excel at vastly different things: memcached is an object cache, while MySQL provides a query cache.

memcached is extremely fast. It uses libevent, which provides a mechanism to execute a callback function when a specific event occurs on a file descriptor, to scale to any number of open connections. On a modern Linux system memcached utilizes epoll, is completely non-blocking for network I/O, ensures memory never gets fragmented, and uses its own slab allocator and hash table to achieve 0(1) virtual memory allocation.

How it install it on Linux server ?

  • Install dependency software (Libevent)
#curl -O http://monkey.org/~provos/libevent-1.4.9-stable.tar.gz
#tar -xzvf libevent-1.4.9-stable.tar.gz
#cd libevent*
#./configure
#make
#make install

  • Now let’s download the newest Memcached source

#curl -O http://www.danga.com/memcached/dist/memcached-1.3.0.tar.gz
#tar zxf memcached-1.3.0.tar.gz
#cd memcached-1.3.0
#./configure
#make
#make install
  • Then add /usr/local/lib to LD_LIBRARY_PATH in your .bash_profile

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH

How it Works

First, you start up the memcached daemon on as many spare machines as you have. The daemon has no configuration file, just a few command line options, only 3 or 4 of which you’ll likely use:

Run Memcached as a daemon (d = daemon, m = memory, u = user, l = IP to listen to, p = port)

#memcached -d -m 1024 -u root -l 127.0.0.1 -p 11211 –u nobody

This starts memcached as a daemon (-d) on the IP address and port specified with -l and -p, respectively, running as the user nobody (-u), allocating 1024  for object storage (-m). You should adjust the amount of storage to suit your needs; many memcached installs run with 4 GB. Once you are comfortable with your startup options, add the appropriate command to your startup scripts.

Create a /etc/init.d/memcached file and add above line to start memcached when the server boots

With memcached installed and running, it’s time to get PHP talking to the object cache. While multiple PHP API exists, the one in the PECL repository is recommended. If you are running a newer version of PHP, installation is as simple as:

# pecl install memcache

Or you can use following steps to install PECL memcache manually.

#cd /usr/local/src
#curl -O http://pecl.php.net/get/memcache
#tar zxvf memcache*
#cd memcache-*
#phpize
#./configure
#make && make install

Now we have to make sure PHP loads the newly built memcache.so library by adding the following line to php.ini:

extension=memcache.so

Now restart Apache:

Service httpd restart

Once it sucussfully install you can create phpinfo() on your webserver should now confirm that memcache is installed.

memcache How to install memcache on linux server?

Regards
AlexP