pantz.org banner
PHP tuning tips
Posted on 11-03-2002 02:14:00 UTC | Updated on 11-03-2002 02:14:00 UTC
Section: /software/php/ | Permanent Link

PHP scripts take a lot more horsepower (cpu and ram) to run that regular static webpages. All code has to be processed on the fly when the page request is made. The ability to have a dynamic website is what makes investing in more cpu and ram worth it. Below are some tips on how to get the best performance when using PHP.

1. The bottle neck for PHP scripts is the CPU unlike HTML pages. So get the fastest CPU you can afford. If your going to be doing static HTML files try to get as much ram as you can afford.

2. Enable HTML compression with ob_gzhandler(). This function is designed to check the Content-Encoding header for deflate or gzip, and automatically compresses the output using the supported encoding. Using it is as simple as turning output buffering on, and setting it as the output handler function: ob_start("ob_gzhandler"); or in the php.ini file with the line: output_handler = ob_gzhandler;.You might want to test this first using ob_start to see if it helps with the download time on larger text output. Also only use this on PHP version 4.1.0 or above and you will need zlib support compiled in to PHP. gzip'ed output is supported by IE 4.0 and higher, Netscape 4.x and Mozilla. Also look into turning compression on with your webserver. For example with lighttpd there is a module called mod_compress. It will compress all pages requested from the webserver and put them in a compressed file on the webserver. Then that file is served out instead of compressing the file each time a request comes in.

3. Use PHP caching software to speed up your scripts.These cache the PHP scripts so they don't have to be compiled everytime they are executed. Some examples of this software are: PHP Accelerator,Zend Accelerator,Afterburner Cache,Turck MMCache, and APC. I've read PHP Accelerator is the best. Most will give a 25-100% improvement in speed. If you run PHP scripts that access a database backend you also might want to check out memchached. Memcached is a distributed memory object caching system intended for use in speeding up dynamic web applications by alleviating database load.

4. Use version 2.0 of apache if you can and compile PHP into it. Apache 2.0 uses threads and improves speed.

5. Switch from file based sessions to shared memory sessions. Compile PHP with the --with-mm option and set session.save_handler=mm in php.ini. Use this feature on PHP 4.2.0 or above.

6. Use output buffering via the ob_start() function. This may speed up your PHP code by 5-15% if you like to use print or echo statements in your code. If your already using ob_gzhandler (mentioned above) as a function or as a output handler then you don't need to use ob_start because it's already being used.

7. The PHP development team recommends compiling PHP4 with the following settings --enable-inline-optimization --disable-debug.

Reddit!

Related stories


RSS Feed RSS feed logo

About


3com

3ware

alsa

alsactl

alsamixer

amd

android

apache

areca

arm

ati

auditd

awk

badblocks

bash

bind

bios

bonnie

cable

carp

cat5

cdrom

cellphone

centos

chart

chrome

chromebook

cifs

cisco

cloudera

comcast

commands

comodo

compiz-fusion

corsair

cpufreq

cpufrequtils

cpuspeed

cron

crontab

crossover

cu

cups

cvs

database

dbus

dd

dd_rescue

ddclient

debian

decimal

dhclient

dhcp

diagnostic

diskexplorer

disks

dkim

dns

dos

dovecot

drac

dsniff

dvdauthor

e-mail

echo

editor

emerald

encryption

ethernet

expect

ext3

ext4

fat32

fedora

fetchmail

fiber

filesystems

firefox

firewall

flac

flexlm

floppy

flowtools

fonts

format

freebsd

ftp

gdm

gmail

gnome

google

gpg

greasemonkey

greylisting

growisofs

grub

hacking

hadoop

harddrive

hba

hex

hfsc

html

html5

http

https

hulu

idl

ie

ilo

intel

ios

iperf

ipmi

iptables

ipv6

irix

javascript

kde

kernel

kickstart

kmail

kprinter

krecord

kubuntu

kvm

lame

ldap

linux

logfile

lp

lpq

lpr

maradns

matlab

memory

mencoder

mhdd

mkinitrd

mkisofs

moinmoin

motherboard

mouse

movemail

mplayer

multitail

mutt

myodbc

mysql

mythtv

nagios

nameserver

netflix

netflow

nginx

nic

ntfs

ntp

nvidia

odbc

openbsd

openntpd

openoffice

openssh

openssl

openvpn

opteron

parted

partimage

patch

perl

pf

pfflowd

pfsync

photorec

php

pop3

pop3s

ports

postfix

power

procmail

proftpd

proxy

pulseaudio

putty

pxe

python

qemu

r-studio

raid

recovery

redhat

router

rpc

rsync

ruby

saltstack

samba

schedule

screen

scsi

seagate

seatools

sed

sendmail

sgi

shell

siw

smtp

snort

solaris

soundcard

sox

spam

spamd

spf

spotify

sql

sqlite

squid

srs

ssh

ssh.com

ssl

su

subnet

subversion

sudo

sun

supermicro

switches

symbols

syslinux

syslog

systemd

systemrescuecd

t1

tcpip

tcpwrappers

telnet

terminal

testdisk

tftp

thttpd

thunderbird

timezone

ting

tls

tools

tr

trac

tuning

tunnel

ubuntu

unbound

vi

vpn

wget

wiki

windows

windowsxp

wireless

wpa_supplicant

x

xauth

xfree86

xfs

xinearama

xmms

youtube

zdump

zeromq

zic

zlib