Programming

CPAN "couldn't Untar" error

I tried to install something via CPAN, but kept getting this error. Even "perl -MCPAN -e 'install CPAN'" gave such error:

Using Tar:/bin/tar xvf /root/.cpan/sources/authors/id/A/AN/ANDK/CPAN-1.9402.tar:
Couldn't untar /root/.cpan/sources/authors/id/A/AN/ANDK/CPAN-1.9402.tar

It wasn't permission, because I was running from root. Maybe the memory. Since this is a OpenVZ container, we would check the /proc/user_beancounters

# cat /proc/user_beancounters

Gprof for Benchmarking C and C++ code

First, you compile the program using "-pg" option:

$ gcc -pg -o a.out test.cc

or 

$ g++ -pg -o a.out test.cpp

Then run the program:

$ a.out

This will generate a file "gmon.out". We will use gprof to view it:

$ gprof a.out gmon.out

Read the man page of gprof to understand the output.

Install Net::Packet

We were not able to install the CPAN module Net::Packet. The error messages indicated that it could not find Net::Libdnet module.

Next, we tried to install Net::Libdnet, but got the error "Libdnet.xs:37:18: error: dnet.h: No such file or directory". That means, we are missing a libdnet.

So, we installed libdnet through yum (from "epel" repos):

# yum install libdnet libdnet-devel

("epel" repos is the Fedora extra package repos).

Perl Socket Shutdown and Close

This discussion http://www.perlmonks.org/?node=108244 explains nicely that we need to do shutdown and close after we are done with a socket:

shutdown on a socket is similar to close on a pipe in what information it gives to the program on the other side. But it does not close the file handle.

WWW::Curl

I tried to install this module WWW::Curl via cpan, but failed on both Centos 4 and Centos 5. Instead of digging for the fix, I just enabled rpmforge repository, and installed through yum:

# yum install perl-WWW-Curl

LWP with Proxy

LWP Cookbook has the example on how to use proxy for HTTP request.

Here are some more examples:

To connect to an HTTP proxy using LWP, here is what you do:

Install PHP-uploadprogress on CentOS

To install the PECL package uploadprogress on CentOS, we do:

  1. Yum up some packages:
    # yum install php-pear php-devel httpd-devel
  2. Install uploadprogress through PEAR:
    # pear install pecl/uploadprogress
  3. Tell PHP to load uploadprogress:
    # echo extension=uploadprogress.so > /etc/php.d/uploadprogress.ini
  4. Restart Apache:
    # /sbin/service httpd graceful

 

 

Install Erlang

You could download the source package from http://www.erlang.org/download.html, then follow the README in the package and install. You will need at least these packages: ncurses-devel, openssl-devel, unixODBC, java-1.xx-openjdk-devel.

Or, you could use the pre-packaged ones. On CentOS 5, you can install the fedora repos, and then yum install the Erlang from there:

# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarc...

Getting Started with Erlang

 Books:

Articles and blogs:

Install PHP-APC on CentOS

  1. Yum up some packages:
    yum install make php-pear php-devel httpd-devel
  2. Install APC using pear (the pear installer is smarter than the pecl installer):
    When the installer asks about APXS, say ‘no’. 
    pear install pecl/apc
  3. Tell PHP to load APC:
    echo extension=apc.so > /etc/php.d/apc.ini
  4. Edit the file /etc/php.d/apc.ini, and add the following lines:
    apc.ttl="7200"
    apc.user_ttl="7200"
    apc.shm_segments="3"