Sunday, May 20, 2007

what is web?

http://www.youtube.com/watch?v=NLlGopyXT_g







thanks to xaoc.

php performance (code)

require_once "./a.php";
require_once "a.php";

php_version() = PHP_VERSION constant
php_uname(‘s’) = PHP_OS constant
php_sapi_name() = PHP_SAPI constant

// Slow
if (preg_match("!^foo_!i", "FoO_")) { }
// Much faster
if (!strncasecmp("foo_", "FoO_", 4)) { }

// Slow
if (preg_match("![a8f9]!", "sometext")) { }
// Faster
if (strpbrk("a8f9", "sometext")) { }

// Slow
if (preg_match("!string!i", "text")) {}
// Faster
if (stripos("text", "string") !== false) {}

$text = preg_replace( "/\n/", "\\n", $text);
In this case it would be simpler and to mention faster to use a regular str_replace()
$text = str_replace( "/\n/", "\\n", $text);

$rep = array( '-' => '*', '.' => '*' );
if ( sizeof( $globArr ) > 1 ) {
$glob = "-" . strtr( $globArr[1], $rep );
} else {
$glob = strtr( $globArr[0], $rep );
}
if ( sizeof( $globArr ) > 1 ) {
$glob = "-" . strtr( $globArr[1], '-.', '**' );
} else {
$glob = strtr( $globArr[0], '-.', '**' );
}

// The Good
if (!strncmp(PHP_OS, 'WIN', 3)) {
if (!strncasecmp(PHP_OS, 'WIN', 3)) {
// The Bad
if (substr(PHP_OS, 0, 3) == 'WIN') {
if (strtolower(substr(PHP_OS, 0, 3))) == 'win') {
// And The Ugly
if (preg_match('!^WIN!', PHP_OS)) {
if (preg_match('!^WIN!i', PHP_OS)) {

if (substr($class, -15) != 'text')
/* == */
if (substr_compare($class, 'text', -15))


References can be used to simply & accelerate access
to multi-dimensional arrays.
$a['b']['c'] = array();
// slow 2 extra hash lookups per access
for($i = 0; $i < 5; $i++)
$a['b']['c'][$i] = $i;
// much faster reference based approach
$ref =& $a['b']['c'];
for($i = 0; $i < 5; $i++)
$ref[$i] = $i;

all info from slides and other sources Ilia Alshanetsky

Saturday, May 19, 2007

php performance (environment)

with this article i start post useful tips for optimize your LAMP applications. all info i grab on net from sites, blogs, etc. be sure, that you check all of this variables what they do to avoid problems.

this can be done in php.ini, inside your scripts or in .htaccess

<IfModule mod_php5.c>
php_value expose_php 0
</IfModule>


register_globals = Off
magic_quotes_gpc = Off
expose_php = Off
register_argc_argv = Off
always_populate_raw_post_data = Off
session.use_trans_sid = Off
session.auto_start = Off
session.gc_divisor = 1000 or 10000

Thursday, May 17, 2007

step 2 — compiling apache 2.0.59 on debian linux

download source from apache (switzerland mirror, you can choose best for you here)
wget http://mirror.switch.ch/mirror/apache/dist/httpd/httpd-2.0.59.tar.bz2

extracting from archive
tar -xvvf httpd-2.0.59.tar.bz2

change into dir
cd httpd-2.0.59

try to config source. here i specify modules for me: rewrite - for good-looking urls, deflate - for compression, headers - to change headers, info - apache informations (i use it for debug).
./configure --prefix=/usr/local/httpd --enable-rewrite --enable-deflate --enable-headers --enable-info

if you passed configure, can go to make. (for dual PII-350, 512 Mb it takes ~10 min)
make -j4

finally, install
make install

editing conf
vi /usr/local/httpd/conf/httpd.conf

if you want apache auto start:
copy start program to init.d
cp /usr/local/httpd/bin/apachectl /etc/init.d
update startup conf
update_rc.d apachectl defaults 19

test run
/etc/init.d/apachectl start

install instructions config help

/usr/local/httpd/conf/httpd .conf
/usr/local/httpd/bin/apachectl start

another help links
apachedev.ru

step 1 — compiling mysql 5.0.41 on debian linux

mysql help about install from source

wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.41.tar.gz/from/http://mirror.switch.ch/ftp/mirror/mysql/

tar -xvvf mysql-5.0.41.tar.gz

./configure --prefix=/usr/local/mysql --with-collation=latin1_general_ci

packages that may be need: libncurses5-dev

make -j4

make install

useful options:
--localstatedir=/usr/local/mysql/data
--enable-thread-safe-client
--with-low-memory
--prefix=/usr/local/mysql
--with-charset=latin1
--with-collation=latin1_general_ci
--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
--with-client-ldflags=-all-static
--with-mysqld-ldflags=-all-static
--with-openssl
--with-mysql-user=mysql
--enable-assembler
--with-mysqld-ldflags=-all-static # not for user-defined functions
--with-unix-socket-path=/tmp/mysql.sock
Where to put the unix-domain socket. SOCKET must be
an absolute file name.

after all done, check your /etc/mysql/my.cnf (server specific options) and /etc/my.cnf (global options) for same socket path. i found that in global conf, socket placed in /tmp/mysql.sock, but server specific - /var/run/mysqld/mysqld.sock. that make error when you trying to run mysql tool. if you do not want to change - workaround is to use "-S socket_path" .