vim /etc/nginx/conf.d/virutal.conf
server {
listen 80;
server_name my-helper.com;
rewrite ^/(.*) http://www.my-helper.com/$1 permanent;
}

server {
listen 80;
server_name www.my-helper.com;
access_log /var/www/vhosts/my-helper.com/logs/access.log;
error_log /var/www/vhosts/my-helper.com/logs/error.log;
location / {
root /var/www/vhosts/my-helper.com/htdocs/;
index index.php;
}
}

Reference:
http://articles.slicehost.com/2009/2/25/centos-nginx-virtual-hosts

1. Enable EPEL repo (ref: http://www.cyberciti.biz/faq/rhel-fedora-centos-linux-enable-epel-repo/)

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-6.noarch.rpm

2. Install nginx

yum install nginx

3. Start nginx

/etc/init.d/nginx

Reference:
http://www.ibualoy.net/blog/itech/linux/167-how-to-configure-nginx-and-apache-on-debian
http://articles.slicehost.com/2008/12/17/centos-installing-nginx-via-yum
http://www.cyberciti.biz/faq/rhel-fedora-install-configure-nginx-php5/

DHCP:

vim /etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=dhcp
ONBOOT=yes

/etc/init.d/network restart

Static IP:

vim /etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.10
NETWORK=192.168.1.0
NETMASK=255.255.255.0
GATEWAY=192.168.1.1

/etc/init.d/network restart

/Library/WebServer/Documents/

Install VLD

wget http://pecl.php.net/get/vld
tar xzf vld-0.11.1.tgz
cd vld-0.11.1
phpize
./configure
make install

Enable VLD

vim /etc/php.ini
extension=vld.so

Use VLD

php -dvld.active=1 test.php
php -dvld.active=1 -dvld.verbosity=3 test.php

If the content of a file is long, the performance of fgets() will be poor. Let's see this example:

$ts = microtime(true);
$fh = fopen('input.in', 'r');
for ($i = 0; $i < 100000; $i++) fgets($fh, 1000000);
printf("%.4f\n", microtime(true) - $ts);

Result:

8.4704

To improve the performance, we can use file_get_contents() instead.

$ts = microtime(true);
$lines = explode("\n", file_get_contents('input.in'));
printf("%.4f\n", microtime(true) - $ts);

Result:

0.0495

When the array size is large, the performance of array_shift() will become poor. Let's see the following example:

$a = range(0, 100000);

$ts = microtime(true);
for ($i=0; $i<100000; $i++) $tmp = array_shift($a);
printf("array_shift=%.4f\n", microtime(true) - $ts);

Result:

array_shift=200.3999

It took 200 seconds which is totally unacceptable. Therefore, if you need to run array_shift() inside a loop, I would suggest doing that in another way. For example:

$a = range(0, 100000);

$pos = 0;
function shift($array) {
return $array[$pos++];
}

$ts = microtime(true);
for ($i=0; $i<100000; $i++) $tmp = shift($a);
printf("shift=%.4f\n", microtime(true) - $ts);

Result:

shift=0.2817

1. Download php from http://www.php.net/releases/

2. Unpack the tarball to your home directory

tar -xjf php-5.2.10.tar.bz2

3. Get module list

php -m | grep -v -e Modules] -e ^$ > php-default-modules

4. Create a configure script

for i in $(cat php-default-modules); do echo -n "--with-$i ">> phpconfigure.sh ;done

5. Edit phpconfigure.sh and insert these 2 lines to the beginning of the file

#!/bin/bash
./configure

6. Run the configure script

./phpconfigure.sh

7. Correct the errors with the help of this command:

./configure --help

To correct the errors, you may need to replace '--with' with '--enable', and remove those modules that are enabled by default.

8. Add other options that you need, such as --enable-safe-mode

9. Create and run phpinfo.php

echo phpinfo();

10. Grab the configure entries from phpinfo.php. Remember not to include '–with-apxs2=/usr/sbin/apxs', and Make sure to change '–with-config-file-path=/etc' and '–with-config-file-scan-dir=/etc/php.d'.

A sample phpconfigure.sh

#!/bin/bash
./configure --prefix=/usr/share --datadir=/usr/share --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --cache-file=../config.cache --with-libdir=lib64 --includedir=/usr/include --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --with-config-file-path=/etc/php52 --with-config-file-scan-dir=/etc/php.5.2.d --with-jpeg-dir=/usr --enable-force-cgi-redirect --enable-discard-path --with-bz2 --enable-calendar --enable-exif --enable-ftp --with-gd --with-gettext --with-gmp --with-iconv --enable-mbstring --with-mcrypt --with-mysql=/usr/bin/ --with-mysqli --with-openssl --with-pdo_mysql --with-PDO_ODBC --with-pdo_sqlite --enable-shmop --enable-sockets --with-xmlrpc --with-xsl --enable-zip --with-zlib

11. Run ./phpconfigure.sh again until all errors are fixed.

12. Run 'make'.

13. Fix the errors.

14. Run 'make' again until all errors are fixed.

15. Duplicate php.ini

mkdir /etc/php52/
cp php.ini-dist /etc/php52/php.ini

16. Duplicate the additional .ini files

mkdir /etc/php.5.2.d
cp /etc/php.d/*.* /etc/php.5.2.d/

17. Change permission of the cgi-bin folder

chmod 755 /var/www/vhosts/domain.com/cgi-bin

18. Copy the php-cgi to the cgi-bin folder

cp sapi/cgi/php-cgi /var/www/vhosts/domain.com/cgi-bin/
chown domain.psacln /var/www/vhosts/domain.com/cgi-bin/php-cgi
chmod 755 /var/www/vhosts/domain.com/cgi-binphp-cgi

19 . Create the apache config file

vim /var/www/vhosts/domain.com/conf/vhost.conf
ScriptAlias /cgi-bin/ /var/www/vhosts/domain.com/cgi-bin/
Action php52-cgi /cgi-bin/php-cgi
AddHandler php52-cgi .php

20. Ask Plesk to reconfigure the domain

/usr/local/psa/admin/bin/httpdmng --reconfigure-domain domain.com

Reference:
http://mossiso.com/2009/09/02/multiple-php-instances-with-one-apache.html
http://kb.parallels.com/en/430

When the array size is large, performance of the built-in function in_array() will be extremely poor. To solve this problem, we can implement a custom in_array() function using hash maps. Here is the source code:

$map = array();
foreach($a as $val) $map[$val] = 1;
function better_in_array($needle, $map) {
return isset($map[$needle]);
}

Let's compare the performance now:

$a = array();
for ($i=0; $i<100000; $i++) $a[$i]=uniqid(rand());

function better_in_array($needle, $map) {
return isset($map[$neddle]);
}

$ts = microtime(true);
for ($i=0; $i<1000; $i++) in_array($i, $a);
printf("in_array=%.4f\n", microtime(true) - $ts);

$ts = microtime(true);
$map = array();
foreach($a as $val) $map[$val] = 1;
for ($i=0; $i<1000; $i++) better_in_array($i, $map);
printf("better_in_array=%.4f\n", microtime(true) - $ts);

Result:

in_array=17.8276
better_in_array=0.0706

If you get the error "WARNING: You are using obsolete option, use corresponding option of httpdmng." when you run this command:

/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=domain.com

you should use the following command instead:

/usr/local/psa/admin/bin/httpdmng --reconfigure-domain domain.com