Monday, February 27, 2012

PHP : Stop Notice and Variable Warnings in Error Log Files

PHP: Stop Notice and Variable Warnings in Error Log Files

by Vivek Gite on December 20, 2008 · 6 comments
Q. I'm using error logging in place of error displaying on production web sites. However, I do not want to see error messages about the use of uninitialized variables. I'd like to see all critical errors, except for notices and coding standards warnings. How do I disable error messages?

A. PHP provides various levels of error reporting using a bit-field as follows:

Error BitPurpose
E_ALLAll errors and warnings (doesn't include E_STRICT)
E_ERRORFatal run-time errors
E_WARNINGRun-time warnings (non-fatal errors)
E_PARSECompile-time parse errors
E_NOTICE Run-time notices (these are warnings which often result from a bug in your code, but it's possible that it was intentional (e.g., using an uninitialized variable and relying on the fact it's automatically initialized to an empty string)
E_STRICTRun-time notices, enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.
E_CORE_ERRORFatal errors that occur during PHP's initial startup
E_CORE_WARNINGWarnings (non-fatal errors) that occur during PHP's initial startup
E_COMPILE_ERRORFatal compile-time errors
E_COMPILE_WARNINGCompile-time warnings (non-fatal errors)
E_USER_ERROR User-generated error message
E_USER_WARNING User-generated warning message
E_USER_NOTICE User-generated notice message

Show only errors

Open /etc/php.ini file
# vi /etc/php.ini
Set error_reporting as follows:
error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
Alternately, you can show all errors, except for notices and coding standards warnings
error_reporting = E_ALL & ~E_NOTICE
Save and close the file. Restart apache web server:
# /etc/init.d/httpd restart

Wednesday, February 8, 2012

Find Memory Usage

Memory is one of the most critical resource components on a server to ensure that the smooth and fast operation. Thus, the availability of adequate and abundant physical memory size is vital especially for any server, especially high load web host that are also running database server such as Oracle or MySQL, which is famous for memory intensive. Linux, including CentOS which is popular on cPanel and Plesk web hosting server, comes with several commands and tools to check memory usage on server.

free
free command displays amount of total, free and used physical memory (RAM) in the system, as well as shoing information on shared memory, buffers, cached memory and swap space used by the Linux kernel.
Syntax of free
free -[options]
Example usage of free
free -m
The command will display information about physical memory in MB.
free -m -s 5
The command will activate continuous polling delay at 5 seconds apart, and then display memory status in megabytes on terminal. Any floating point number for delay can be specified.
free -t -m
Same with “free -m”, but -t switch will display a line containing the totals of physical memory and swap space.
vmstat
vmstat reports report virtual memory statistics, which has information about processes, swap, free, buffer and cache memory, paging space, disk IO activity, traps, interrupts, context switches and CPU activity. With vmstat command, administrators can has instantaneous reports on memory usage.
Syntax of vmstat
vmstat -[options] [delay count]
Example usage of vmstat
vmstat
The command will display report based on averages since last reboot.
vmstat 5
The command will pool average system resources usage level for a sampling period of 5 seconds at interval of 5 seconds, except the first result that is averages since the last reboot.
top
top command displays dynamic real-time view of the running tasks managed by kernel and system information in Linux system. The memory usage stats by top command include real-time live total, used and free physical memory and swap memory with their buffers and cached memory size respectively.
Syntax and example usage of top
top
Using top is simple, simply type top at command shell, and constantly update stats page will be shown.
ps aux
ps command reports a snapshot on information of the current active processes. Advantage of ps command is that system admins will be able to see where the memory is used. ps will show the percentage of memory resource that is used by each process or task running in the system. With this command, top memory hogging processes can be identified.
Syntax and example of ps aux
aux is actually already the options for ps command to see every process on the system. So the typical command to type the following in the command shell:
ps aux
To see only the memory resources occupied by each category of processes, such as Apache httpd, MySQL mysqld or Java, use the following command:
ps aux | awk '{print $4"\t"$11}' | sort | uniq -c | awk '{print $2" "$1" "$3}' | sort -nr
The all mentioned ways of check memory usage should works on most Unix and Linux variant of operating systems. However, if you’re running a VPS (Virtual Private Server) or VDS (Virtual Dedicated Server) or Hybrid Server, especially those powered by Virtuozzo or OpenVZ, the above commands will retrieve data from the host machine, i.e. the entire server the virtual environment is running on. In these virtualization system, the memory usage info has to be calculated from control panel or /proc/user_beancounters file

INstalling Desktop effects (compiz) for Fedora

yum install compiz


#To setup compiz-fusion for Gnome you need to install these additional packages:
 
su-
yum install -y ccsm emerald-themes compizconfig-backend-gconf fusion-icon-gtk emerald compiz-fusion compiz-fusion-gnome libcompizconfig compiz-gnome compiz-bcop compiz compizconfig-python compiz-fusion-extras compiz-fusion-extras-gnome 
  
#To setup compiz-fusion for KDE you need to install these additional packages:

su-
yum install -y ccsm emerald-themes compizconfig-backend-kconfig fusion-icon-qt emerald compiz-fusion libcompizconfig compiz-bcop compiz compizconfig-python compiz-fusion-extras  compiz-kde compiz-manager

#
To setup compiz-fusion for both Gnome and KDE you need to install these additional packages:

su -
yum install -y ccsm emerald-themes compizconfig-backend-kconfig compizconfig-backend-gconf fusion-icon* emerald compiz-fusion compiz-fusion-gnome libcompizconfig compiz-gnome compiz-bcop compiz compizconfig-python compiz-fusion-extras compiz-fusion-extras-gnome compiz-kde compiz-manager

Wednesday, February 1, 2012

find runnig time of a PID and process informations

Find runnig time of  a PID

 
ps -eo pid,etime | grep pidnumber
 

Task: UNIX List Open Files For Process

First use ps command to get PID of process, enter:
$ ps -aef | grep {process-name}
$ ps -aef | grep httpd


 Next pass this PID to pfiles command,
$ pfiles {PID}
$ pfile 3533



Task: Linux List Open Files For Process

First you need to find out PID of process. Simply use any one of the following command to obtain process id:
# ps aux | grep {program-name}
OR
$ ps -C {program-name} -o pid=
For example, find out PID of firefox web-browser, enter:
$ ps -C firefox -o pid=
Output:
 7857
To list opne files for firefox process, enter:
$ ls -l /proc/7857/fd
Sample output:
total 0
lr-x------ 1 vivek vivek 64 2008-03-05 22:31 0 -> /dev/null
l-wx------ 1 vivek vivek 64 2008-03-05 22:31 1 -> pipe:[18371]
lr-x------ 1 vivek vivek 64 2008-03-05 22:31 10 -> /usr/lib/firefox/firefox
l-wx------ 1 vivek vivek 64 2008-03-05 22:31 2 -> pipe:[18371]

lsof command

lsof command list open files under all Linux distributions or UNIX like operating system. Type the following command to list open file for process ID 351:
$ lsof -p 351