Unix / Linux

PHP OPCodes Cached with APC – part 2

Before reading this post, I recommend going over part 1 PHP OPCodes Cached with APC – part 1

In the first part we tackled what OPCodes are and how APC helps us streamline webserver performance by caching recurring script execution.

In this second part, we will mostly look at the APC configuration main variable and thus further understand how the APC engine works.

APC cache size and shared memory

apc.shm_segments

By default this value is set to ‘1′; that is so say, there would be only one shared memory segment to allocate to the cache

apc.shm.size

This is the size in MB of each shared memory segment. The default is of 30Mb.

Please note that you cannot set a higher value than the maximum size of shared memory segment defined in your kernel distribution.

cat /proc/sys/kernel/shmmax
33554432

Read the rest of this entry »

PHP OPCodes Cached with APC – part 1

There are many caching system in use to optimize the execution of PHP script on busy web/database servers. Today we will focus on the OPcode caching method using APC.

Before we start… what is an OPcode?

The OPcode is an executable code generated each time a PHP script is interpreted and compiled. Each time you visit a webpage, the webserver (apache for example) would generate an OPcode of the PHP script serving your request. They are therefore simply C data structure which are interpreted by the PHP Virtual Machine (Zend Engine).

Now you can imagine, generating the OPcode can be a drain on the server and quite useless if the code does not change often. This is where the OPcode caching system comes into play; but before we go on, let’s see some OPcode example using the Vulcan Logic Disassembler.

First, we create a file test.php in which we will execute a unix ls -l command

test.php – <? system(“ls -l”); ?>

wrk01:/var/www# php -d vld.active=1 test.php
Branch analysis from position: 0
Return found
filename:       /var/www/test.php
function name:  (null)
number of ops:  4
compiled vars:  none
line     #  op                           fetch          ext  return  operands
——————————————————————————-
2     0  SEND_VAL                                                 ‘ls+-l’
1  DO_FCALL                                      1          ’system’
4     2  RETURN                                                   1
3* ZEND_HANDLE_EXCEPTION

Now let’s try a simple ( echo “hello world!” ) Read the rest of this entry »

mcelog – monitor hardware issues

It is often the case to receive a call in the middle of the night or walk into the office and find out a server which failed due to hardware problems.

What is mcelog?

From the project site description

mcelog decodes machine check events (hardware errors) on x86-64 machines running a 64-bit Linux kernel. It should be run regularly as a cron job on any x86-64 Linux system (if it is not in the default packages on your x86-64 distribution, please complain to your distributor). It can also decode machine check panic messages from console logs.

Now before we go on, it is important to understand what MCE is

MCE stands for Machine Check Exception, which is nothing but an AMD/Intel 64bit feature that allows to detect unrecoverable hardware problem such as “Communication errors between the motherboard and the CPU, CPU cache errors, Memory ECC erros etc..”

A common MCE log error would look like this

CPU 0: Machine Check Exception: 0000000400000000<0>
fault: 0000
CPU: 0
EIP: 0010:[mcheck_fault+225/336]
EFLAGS: 00010246
eax: 00000115 ebx: 72000000 ecx: 00000405 edx: 72000000
esi: 00000004 edi: 00000003 ebp: 00000115 esp: c3187f94
ds: 0018 es: 0018 ss: 0018

A program like syslogd will write the message to the console or to the kernel log; if the machine crashes, then only to the console.

mcelog will therefore “decode” those machine event errors, which are saved in the special kernel buffer /dev/mcelog.

Work with mcelog

mcelog should be run as a cron

/usr/sbin/mcelog –generic –ignorenodev –filter >> /var/log/mcelog

Make sure to check the man page of mcelog for all the options.

I would recommend setting up a script to email you in case of alerts or even why not “pipe your mcelog through a socket

That’s it. Hopefully from now, you can catch system, hardware errors before a kernel panic :-)

Cheers,

qtcreator-collec2-ld-returned-1-exit-status

When facing this error…

manually cd into the project QT folder and run “make”… ld would return the library name it isn’t able to locate.

Example:

ali@laptop:~/Documents/Dev/QT-Progs/Test$ make
g++ -Wl,-rpath,/opt/qtsdk-2009.03/qt/lib -o Test main.o testhello.o moc_testhello.o    -L/opt/qtsdk-2009.03/qt/lib -lQtGui -L/opt/qtsdk-2009.03/qt/lib -L/usr/X11R6/lib -pthread -lfreetype -lgobject-2.0 -lSM -lICE -pthread -pthread -lXrender -lfontconfig -lXext -lX11 -lQtCore -lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread
/usr/bin/ld: cannot find -lfreetype
collect2: ld returned 1 exit status
make: *** [Test] Error 1

Note the “cannot find -lfreetype”.. now note it can be any other library, depending on your current system configuration.

In most cases, install the devel package associated with this library.

Debian/Ubuntu “apt-get install libfreetype6-dev” for example.

Now, re-run the “make” and observe for further errors…

How to install Acrobat Reader on Centos

1. go to acrobat.com/reader

2. download the bin linux install file

3. chmod +x AdbeRdr9.1.1-1_i486linux_enu.bin

4. ./AdbeRdr9.1.1-1_i486linux_enu.bin

Extracting files, please wait. (This may take a while depending on the configuration of your machine)

This installation requires 144 MB of free disk space.

Enter installation directory for Adobe Reader 9.1.1 [/opt]

(press enter)

The installation will therefore go on

Installing platform independent files … Done
Installing platform dependent files … Done
Setting up libraries … Done
Setting up desktop and menu icons … Done
Setting up the browser plugin … Done

And that’s it