Topics

network

Install Sphinx 2.0.4 on CentOS 6.2

– Make sure to check CentOS, PHP-FPM, Nginx, memcached and MYSQL posts.

– Get fresh RPM from sphinxsearch.com

– Install Sphinx

rpm -Uhv http://sphinxsearch.com/files/sphinx-2.0.4-1.rhel6.x86_64.rpm

– Create sample MySQL database

Watch log files on Linux server with Swatch 3.2.3

– Make sure to check CentOS, PHP-FPM, memcached and MYSQL posts.

– get a fresh package from Swatch project

wget "http://downloads.sourceforge.net/project/swatch/swatch/3.2.3/swatch-3.2.3.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fswatch%2F&ts=1330806322&use_mirror=garr"
tar xfz swatch-3.2.3.tar.gz 
cd swatch-3.2.3
cpan -i Date::Format File::Tail
cpan -i Date::Manip Date::Calc
cpan -i Test::Inter Test::Pod Test::Pod::Coverage Module::Build
cp /root/.cpan/sources/authors/id/S/SB/SBECK/Date-Manip-* .
tar xfz Date-Manip-*.tar.gz
cd Date-Manip-*
perl Build.PL 
./Build install
cd ..
perl Makefile.PL
make install

– configure swatch

increase linux file descriptors

Check Installing CentOS 6.2 on VMware and mounting partitions with noatime posts.

This is very important performance tuning for any web server more information here

#adduser www first http://gadelkareem.com/2012/02/26/adding-new-users-and-admins-to-linux-server/
ulimit -n unlimited - www
#check default number of concurrently open file descriptors 
cat /proc/sys/fs/file-max
#set the number to high value depending on server config
echo '1773914' > /proc/sys/fs/file-max
echo 'fs.file-max=1773914' >> /etc/sysctl.conf
/sbin/sysctl -w fs.file-max=1773914

Firefox chrome function : Read/write file on disk

tested on Firefox 7.0.1

const Ci = Components.interfaces;  
const Cc = Components.classes;

function ReadWrite( data ){
    
        	try{
                            Components.utils.import("resource://gre/modules/NetUtil.jsm");
                            Components.utils.import("resource://gre/modules/FileUtils.jsm");

                            var file = FileUtils.getFile("ProfD", ["FileName.txt"]);
                            var ostream = FileUtils.openSafeFileOutputStream(file );
                            var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
                                                     createInstance(Ci.nsIScriptableUnicodeConverter);

                            if( data ){
                            
                                    if ( !file.exists() ){
                                            file.create( Ci.nsIFile.NORMAL_FILE_TYPE, 420);
                                    }
                                    converter.charset = "UTF-8";
                                    var istream = converter.convertToInputStream(data);
                                    NetUtil.asyncCopy(istream , ostream, function(status) {
                                                    if (!Components.isSuccessCode(status)) {
                                                            alert( "Error! :" + status );
                                                            return false;
                                                     }
                                    });
                                                                        
                           }else{
                                    var data = '';
                                    var fstream = Cc["@mozilla.org/network/file-input-stream;1"].
                                                  createInstance(Ci.nsIFileInputStream);
                                    var cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].
                                                  createInstance(Ci.nsIConverterInputStream);
                                    fstream.init(file, -1, 0, 0);
                                    cstream.init(fstream, "UTF-8", 0, 0); // you can use another encoding here if you wish

                                    let (str = {}) {
                                          let read = 0;
                                          do { 
                                                read = cstream.readString(0xffffffff, str); // read as much as we can and put it in str.value
                                                data += str.value;
                                          } while (read != 0);
                                    }
                                    cstream.close(); // this closes fstream
                                    return data;

                               }

	}catch(e){
//                          alert( e);
                            return false;
	}
    }

XUL : open URL with a referrer

This is a small function to use in Firefox extension development which makes use of the referrer parameter sent to loadURI() and addTab() functions