Thursday, May 31, 2007

mootools programming help

MooTools is a compact, modular, Object-Oriented javascript framework designed to make writing extensible and compatible code easier and faster. MooTools lets you get the job done efficiently and effectively.



MooTools have great effects, so one time i was need help and found this sites useful for me...
MooTools docs
A Mootools Tutorial :: The "Mootorial"
MOOTOOLS Javascript Examples

in my present work i use another js framework Prototype, so if you want only effects from mootools, you can use moo.fx for this.

Thursday, May 24, 2007

mysql profiling

this is my first post about profiling, so we need to understand what is profiling (performance analysis)?

In software engineering, performance analysis (a field of dynamic program analysis) is the investigation of a program's behavior using information gathered as the program runs, as opposed to static code analysis. The usual goal of performance analysis is to determine which parts of a program to optimize for speed or memory usage.


full article you can find at mysql documentation, here i'll just overview it.

profiling gives us option to understand on timeline our queries, to see resource usage for executed statements. SHOW PROFILES and SHOW PROFILE were added in MySQL 5.0.37 (that's important!).

Profiling is controlled by the profiling session variable, which has a default value of 0 (OFF). Profiling is enabled by setting profiling to 1 or ON.
mysql> SELECT @@profiling;
+-------------+
| @@profiling |
+-------------+
| 0 |
+-------------+
1 row in set (0.00 sec)

mysql> SET profiling = 1;
Query OK, 0 rows affected (0.00 sec)

mysql> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> CREATE TABLE T1 (id INT);
Query OK, 0 rows affected (0.01 sec)

mysql> SHOW PROFILES;
+----------+----------+--------------------------+
| Query_ID | Duration | Query |
+----------+----------+--------------------------+
| 0 | 0.000088 | SET PROFILING = 1 |
| 1 | 0.000136 | DROP TABLE IF EXISTS t1 |
| 2 | 0.011947 | CREATE TABLE t1 (id INT) |
+----------+----------+--------------------------+
3 rows in set (0.00 sec)

mysql> SHOW PROFILE;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| checking permissions | 0.000040 |
| creating table | 0.000056 |
| After create | 0.011363 |
| query end | 0.000375 |
| freeing items | 0.000089 |
| logging slow query | 0.000019 |
| cleaning up | 0.000005 |
+----------------------+----------+
7 rows in set (0.00 sec)

mysql> SHOW PROFILE FOR QUERY 1;
+--------------------+----------+
| Status | Duration |
+--------------------+----------+
| query end | 0.000107 |
| freeing items | 0.000008 |
| logging slow query | 0.000015 |
| cleaning up | 0.000006 |
+--------------------+----------+
4 rows in set (0.00 sec)

mysql> SHOW PROFILE CPU FOR QUERY 2;
+----------------------+----------+----------+------------+
| Status | Duration | CPU_user | CPU_system |
+----------------------+----------+----------+------------+
| checking permissions | 0.000040 | 0.000038 | 0.000002 |
| creating table | 0.000056 | 0.000028 | 0.000028 |
| After create | 0.011363 | 0.000217 | 0.001571 |
| query end | 0.000375 | 0.000013 | 0.000028 |
| freeing items | 0.000089 | 0.000010 | 0.000014 |
| logging slow query | 0.000019 | 0.000009 | 0.000010 |
| cleaning up | 0.000005 | 0.000003 | 0.000002 |
+----------------------+----------+----------+------------+
7 rows in set (0.00 sec)



Here is SQL queries that you need to know:

SELECT @@profiling;

SET profiling = 1;
SET profiling = 0;

SHOW PROFILES;
SHOW PROFILE;
SHOW PROFILE FOR QUERY 1;

/* displays all information */
SHOW PROFILE ALL FOR QUERY 1;
/* displays counts for block input and output operations */
SHOW PROFILE BLOCK IO FOR QUERY 1;
/* displays counts for voluntary and involuntary context switches */
SHOW PROFILE CONTEXT SWITCHES FOR QUERY 1;
/* displays user and system CPU usage times */
SHOW PROFILE CPU FOR QUERY 1;
/* displays counts for messages sent and received */
SHOW PROFILE IPC FOR QUERY 1;
/* displays counts for major and minor page faults */
SHOW PROFILE PAGE FAULTS FOR QUERY 1;
/* displays the names of functions from the source code, together with the name and line number of the file in which the function occurs */
SHOW PROFILE SOURCE FOR QUERY 1;
/* displays swap counts */
SHOW PROFILE SWAPS FOR QUERY 1;

Wednesday, May 23, 2007

SELECT *

i found this haha img on mysql webinars.


this post not about sql error on img but about post subject.
it's ok when your table is

CREATE TABLE `your_table` (
`id` tinyint(3) unsigned NOT NULL auto_increment,
`smthing` tinyint(3) NOT NULL unsigned,
PRIMARY KEY (`id`)
) ENGINE=MyISAM

only two columns and you can use SELECT * and even you can put subj in 10 places, ok? after month, you alter table, add text field. usually, you not remember all places with this code, so in 10 places it overload resource usage with useless traffic between MySQL and application, isn't it? it mean that is always better to do SELECT `id`, `smthing` FROM... - only needed fields.
so, forget to select all!

Tuesday, May 22, 2007

css background lesson

still having problem with background positioning? Web Design 101: Backgrounds

Monday, May 21, 2007

php filter

how you check data coming from user? we have great tool already in php - "Filter Functions".

This extension serves for validating and filtering data coming usually from some insecure source such as user input.



good tutorials you can find here: Zend devzone, PHPro and php doc.

want to learn mysql?

if you really want to understand how mysql stuff works, start read webinars instructions at MySQL AB On Demand Web Seminars.

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" .

Wednesday, May 16, 2007

step 0 — before compiling LAMP on debian linux

before you start any installation, please, update you system. it very helpful - cause you will use during "make" lot of tools such as gcc, libxml, etc.

apt-get update

apt-get upgrade

you probable need root access for linux while all future steps (# sign).