Ulf Wendel

2007/02/02
by admin
1 Comment

About the performance of mysqlnd-5.0.0-alpha

I have written a long, long blog entry How fast is mysqlnd-5.0.0-alpha?.I do not want to spam the Planets with all of it. It’s aimed at PHP and MySQL users that want to hear in detail what we know about the performance of the first alpha release of the MySQL native driver for PHP.

The following table demonstrates pretty well where we are with mysqlnd. For a first alpha it shows an acceptable performance.

As an example of a realistic benchmark, we have followed the decision of the german computer magazine c’t and choosen the Dell DVD Store. Last year a MySQL team had won (german press release) a database performance contest of the magazine and outperformed its competitors by far with an Apache, MySQL and PHP based contest submission. The benchmark is an OLTP-style application that simulates users browsing an online DVD store and purchasing DVDs.

Dell DVD Store results*
ext/mysqli using mysqlnd 10505 opm 100%
ext/mysqli using libmysql 9882 opm 94%
ext/mysql using libmysql 10203 opm 97%

Neither MySQL nor PHP have been tuned for the computer we used for benchmarking. Apache, PHP, MySQL and Mono driver program generating the web request have been running all on the same computer. Not the absolute figues are important. It is important to see that mysqlnd seems to be a bit faster than libmysql, at least as fast as.

We have done some micro-benchmarking that seems to prove that we have been able to make mysqlnd faster than libmysql. Some of the figures are impressive, for example mysqli_affected_rows() seems to be more than twice as fast as before. When fetching buffered result sets similar performance improvements seem possible. You can find details in How fast is mysqlnd-5.0.0-alpha?

However, in the end it depends very much on your applications and environments, if you will see any considerable performance improvements. It’s impossible to to promise a general speed-up.
< &p>
Our request to you is to do your own benchmarking and to tell us what you find. We are eager to hear from you on the mailing list php@lists.mysql.com (see also http://lists.mysql.com/php). Enjoy the weekend!

2007/02/02
by admin
Comments Off on How fast is mysqlnd-5.0.0-alpha?

How fast is mysqlnd-5.0.0-alpha?

Imagine you’re approaching the planned release date. It is less than one week to go and you have just stopped doing micro-benchmarks only and started with more realistic benchmarks. As an example of a realistic benchmark, we have followed the decision of the german computer magazine c’t and choosen the Dell DVD Store. Last year a MySQL team had won (german press release) a database performance contest of the magazine and outperformed its competitors by far with an Apache, MySQL and PHP based contest submission. The benchmark is an OLTP-style application that simulates users browsing an online DVD store and purchasing DVDs.

However, I installed the benchmark on a computer and the first result I got with the contest submission setup was -40%. Minus 40%.

It seemed that our new development was 40% slower than your old, established solution! All previous benchmarks, which we had started to run long ago in parallel to the regular development, had shown that we are in the same league than before. Sometimes about 10% slower, sometimes faster. But the in same league. No need to worry, no need to shift development focus, no such alarming results.

On January, 26th the first figures we got from the Dell DVD Store benchmark have been about 5.500 operations per minute (opm) for ext/mysqli using mysqlnd (100%), roughly 7.800 operations per minute for ext/mysqli using libmysql, the MySQL Client Libarary, (~140%) and approximately 8.000 opm for ext/mysql using libmysql (~145).

It has been only five days to the release and we have simply not been there with our product. How could we fail so miserably? Luckily, this story has a good ending. One day before the launch, on January 31st, we repeated the benchmark and got:

Dell DVD Store results*
ext/mysqli using mysqlnd 10505 opm 100%
ext/mysqli using libmysql 9882 opm 94%
ext/mysql using libmysql 10203 opm 97%

Neither MySQL nor PHP have been tuned for the computer. Apache, PHP, MySQL and Mono driver program generating the web request have been running all on the same computer.

Strike.

Working with senior developers and managers

On Friday, 26th I was pretty frustrated. I repeated the benchmark on another computer and I got the same result: 35% behind. On Saturday, Georg called me around lunch time: “I found the bottleneck”. As you know from above, he and Andrey fixed it.

Later on we realized that on both boxes that we used for benchmarking we had other processes running in the background. We have grossly underestimated their influence, because we did run the benchmark on a computer with several CPUs and 8GB of memory which seemed to be idle all the time (load < 0.2 )). Later in the evening, when people had stopped working on the computer, Georg could not confirm the first result but saw us more like 10% behind. This is similar to the impressions we had got before in our micro-benchmarks.

The lesson for you is not to make the same mistake! If you run benchmarks, run on a dedicated machine. No other people should be working on the computer, no KDE or any other background processing, nothing that could give you faulty results. The above figures from the 31st are from the same box but with all background processes stopped and several minutes of runtime to ensure hot caches.

Is a PHP mysqlnd applcation faster than a PHP libmysql application?

Unfortunately, there is no simple answer to the question if mysqlnd is faster than libmysql or not. For the Dell DVD Store mysqlnd is about as fast as libmysql. The figures for ext/mysqli using mysqlnd, ext/mysqli using libmysql and ext/mysql are all within 5%. This is not enough to promise that all of your PHP MySQL applications will become suddenly faster.

However, mysqlnd has a great potential and has become faster than libmysql in many cases. Here is one example from our micro-benchmarks. It comes from an AMD64 3000+ computer.

  ext/mysqli using libmysql ext/mysqli using mysqlnd
100 rows: 10000x overall 9.17570s 100% 4.20944s 45%
100 rows: 10000x affected_rows() 5.96595s 100% 2.71338s 45%

I’m sorry to say, there is a “but” here again. The first problem is that no real-life application calls affected_rows() 10.000 times in a loop. The second problem is that although mysqlnd is more than twice as fast as libmysql, you save only (5.96595 – 2.71338) / 10000 = 0.000325257 seconds execution time per mysqli_affected_rows() call on the computer that has performed this benchmark.

Of course, the 0.0003 seconds sum up with every script execution and every web server process/thread. But you have to understand that this significant improvement in the performance of mysqli_affected_rows() makes only a fraction of the total execution time for a web application. If wou want to make your web application really fast, avoid any dynamic content at all. Here are some figures from a quick test (german text on caching) of the lighttpd web server in 2003:

Static HTML: Hello world! 17000 requests/s 100.00%
PHP: Hello world! 1200 requests/s 7.00%
PHP on a homepage 100 requests/s 0.58%

What sense does it make to get from 100 requests/s and 0.58% to 110 requests/s and per second 0.63%, for example by making mysqli_affected_rows() more than 50% faster? Keep this in mind. We could have made the function even 90% faster and execute at 1/10 or the original time, it does not make your applications suddenly faster. That said, let’s get excited about mysqlnd. Here comes another example of fetching 10 rows with a total size of 1500k each row. Maybe something for those who store images or documents in the database:

  ext/mysqli using libmysql ext/mysqli using mysqlnd
10 row[s]: 1500 k SELECT overall 0.15111s 100% 0.09145s 60%

What has become faster?

Instead of asking if all applications suddenly will execute faster, you should study the performance properties of mysqlnd. The question is what has become faster. And of course, how much. Here we have two good news for you: we have included a set of scripts in the mysqlnd download archive that you can use for micro-benchmarking and we show example results.

The following table shows a list of micro-benchmarks. You will learn in a minute how to run these benchmarks on your computer. But first, let us explain how to interpret the table figures.

For every micro-benchmark the table shows one row. The first rows is about the micro-benchmark ‘georg_bench1.php’. The name of the benchmark is followed by “2 100%”. This tells you that 2 times have been recorded when running the PHP script.

  libmysql mysqlnd
georg_bench1.php 2 100% 0 0% 2 100%
mysqli_fetch_all_vs_fetch_array.php 240 100% 28 11% 212 88%

Each column that follows the “2 100%” shows the binaries that have been used to execute the ‘georg_bench1.php’ micro-benchmark. Here, two binaries are compared. One has been given the label ‘libmysql’ and one has been given the label ‘mysqlnd’. The binary ‘mysqlnd’ has been faster than all other binaries for 2 (= 100%) of the times that have been recorded. Another example is ‘mysqli_fetch_all_vs_fetch_array.php’. For this benchmark mysqlnd has been faster for 212 (= 88%) of the 240 times recorded.

Here is the entire result from a run on my computer. Your computer, might give you different figures and relations. We are curious to hear from you, please tell us on php@lists.mysql.com (see also http://lists.mysql.com/php/.

Note also that this table says nothing about how much mysqlnd was faster or slower in my benchmark.

  libmysql mysqlnd
georg_bench1.php 2 100% 0 0% 2 100%
georg_bench2.php 4 100% 2 50% 2 50%
mysqli_affected_rows.php 4 100% 0 0% 4 100%
mysqli_data_seek_random.php 156 100% 0 0% 156 100%
mysqli_data_seek_sequential.php 52 100% 0 0% 52 100%
mysqli_fetch_all_vs_fetch_array.php 240 100% 28 11% 212 88%
mysqli_fetch_field_direct.php 32 100% 2 6% 30 93%
mysqli_fetch_long_buffered.php 47 100% 12 25% 35 74%
mysqli_fetch_long_unbuffered.php 47 100% 34 72% 13 27%
mysqli_insert_id.php 2 100% 0 0% 2 100%
mysqli_query_insert_varchar.php 90 100% 6 6% 84 93%
mysqli_select_varchar_buffered.php 105 100% 8 7% 97 92%
mysqli_select_varchar_unbuffered.php 65 100% 10 15% 55 84%
mysqli_query_update_varchar.php 100 100% 8 8% 92 92%
mysqli_real_query.php 100 100% 0 0% 10 100%
mysqli_variable_command_size.php 84 100% 3 3% 81 96%

Running the hacker’s micro-benchmarks

One way to learn more about the performance about mysqlnd is to do benchmarking on your own. We have included the micro-benchmarks from above in the source distribution of the alpha relase. To run the micro-benchmarks you need to get a copy of PHP6. For example, you can check out a CVS copy. Create two copies to be able to compile two PHP binaries with a different code base. One using the original code and one using a patched mysqlnd version.

nixnutz@linux-eu6p:~/blog> cvs -d :pserver:cvsread@cvs.php.net:/repository checkout php6
cvs checkout: Updating php6
[...]
U TSRM/tsrm_win32.h
nixnutz@linux-eu6p:~/blog> cp -R php6 php6_libmysql
nixnutz@linux-eu6p:~/blog> cp -R php6 php6_mysqlnd
nixnutz@linux-eu6p:~/blog> ls
php6  php6_libmysql  php6_mysqlnd

Get a copy of mysqlnd. You can download it from http://dev.mysql.com/downloads/connector/php-mysqlnd/ or check out the public (read-only) SVN repository as shown below. Then, remove the ext/mysqli directory from the directory php6_mysqlnd and copy the ext/mysqli directory from the mysqlnd distribution in it.

nixnutz@linux-eu6p:~/blog> svn co http://svn.mysql.com/svnpublic/php-mysqlnd/
A    php-mysqlnd/trunk
[...]
Ausgecheckt, Revision 19.
ixnutz@linux-eu6p:~/blog> rm -rf php6_mysqlnd/ext/mysqli
nixnutz@linux-eu6p:~/blog> cp -R php-mysqlnd/tags/release-5.0.0-alpha/ext/mysqli php6_mysqlnd/ext/mysqli
nixnutz@linux-eu6p:~/blog> ls php6_mysqlnd/ext/mysqli
config.m4   INSTALL  mysqli_api.c  mysqli_driver.c  mysqli_embedded.c   mysqli_fe.c      
 mysqli_nonapi.c  mysqli_repl.c    mysqli_report.h   mysqlnd       README
config.w32  LICENSE  mysqli.c      mysqli.dsp       mysqli_exception.c  
mysqli_mysqlnd.h  mysqli_prop.c    mysqli_report.c  mysqli_warning.c  php_mysqli.h  tests

At this point you are ready to compile PHP6 with ext/mysqli using mysqlnd. Go to the PHP6 source directory php6_mysqlnd/ and do the usual compile steps. The configure parameter for mysqlnd are: –with-mysqli –enable-mysqlnd. Unlike normally, you do not specify the path to the tool mysql_config.

nixnutz@linux-eu6p:~/blog> cd php6_mysqlnd
nixnutz@linux-eu6p:~/blog/php6_mysqlnd> ./buildconf --force
nixnutz@linux-eu6p:~/blog/php6_mysqlnd> ./configure --with-mysqli --enable-mysqlnd
nixnutz@linux-eu6p:~/blog/php6_mysqlnd> make
nixnutz@linux-eu6p:~/blog/php6_mysqlnd> ls -la sapi/cli/php
-rwxr-xr-x 1 nixnutz users 13281952 2007-02-02 14:13 sapi/cli/php
nixnutz@linux-eu6p:~/blog/php6_mysqlnd> sapi/cli/php -i | grep mysqlnd
Configure Command =>  './configure' '--with-mysqli' '--enable-mysqlnd'
Client API library version => mysqlnd 5.0.1-alpha - 50100 - $Revision: 18 $
PWD => /home/nixnutz/blog/php6_mysqlnd
_SERVER["PWD"] => /home/nixnutz/blog/php6_mysqlnd
_ENV["PWD"] => /home/nixnutz/blog/php6_mysqlnd

Once you managed to build a first binary that can be used for micro-benchmarking, you need to compile a second one. This time PHP6 with a classical ext/mysqli using libmysql. You can either use the ext/mysqli tree from the PHP CVS or the ext/mysqli tree from the mysqlnd tree. Both trees can be used. I am lazy here and I use the original ext/mysqli tree from the PHP CVS. The important point is to make sure that you get a second binary and to make sure that you do not mix up your setup. I personally like to have two build directories as shown here. So, build a second PHP with the classical configure parameter: –with-mysqli=/path/to/mysql_config .

nixnutz@linux-eu6p:~/blog/php6_mysqlnd> cd ../php6_libmysql/
nixnutz@linux-eu6p:~/blog/php6_libmysql> ./buildconf --force 
nixnutz@linux-eu6p:~/blog/php6_libmysql> ./configure --with-mysqli=/usr/local/mysql/bin/mysql_config       
nixnutz@linux-eu6p:~/blog/php6_libmysql> ls -la sapi/cli/php
-rwxr-xr-x 1 nixnutz users 15178082 2007-02-02 15:55 sapi/cli/php
nixnutz@linux-eu6p:~/blog/php6_libmysql> sapi/cli/php -i | grep mysqli | head -n 2
Configure Command =>  './configure' '--with-mysqli=/usr/local/mysql/bin/mysql_config'
mysqli

Configuring the micro-benchmarks

Now you have two binaries that you can use for benchmarking. The micro-benchmarks used here are very simple. All they do is use the binaries to run a script and let the script record the runtimes in a MySQL database. Then, a complicated script, creates some text and HTML output. How this is done, is explained below. But usually you want to see performance figures and not read long stories about the how.

Go back to the php6_mysqlnd directory into which you had copied the ext/mysqli tree from the mysqlnd distribution and check the tests directory. Inside ext/mysqli/tests/bench you find the framwork that runs the micro-benchmarks. The directory framework/ holds the files of the framework and micro_benches/ holds the scripts that will be benchmarked.

nixnutz@linux-eu6p:~/blog/php6_mysqlnd/ext/mysqli/tests/bench> ls -la
insgesamt 11
drwxr-xr-x 5 nixnutz users  160 2007-02-02 14:03 .
drwxr-xr-x 4 nixnutz users 6264 2007-02-02 14:03 ..
drwxr-xr-x 3 nixnutz users  312 2007-02-02 14:03 framework
drwxr-xr-x 3 nixnutz users 1064 2007-02-02 14:03 micro_benches
-rw-r--r-- 1 nixnutz users 3699 2007-02-02 14:03 README
drwxr-xr-x 7 nixnutz users  328 2007-02-02 14:03 .svn

In the directory framework/, you will find a file ‘config.php’. Adapt it to your needs. Inline comments in the file explain what to do.

nixnutz@linux-eu6p:~/blog/php6_mysqlnd/ext/mysqli/tests/bench/framework> ls -la
insgesamt 56
[...]
-rw-r--r-- 1 nixnutz users  2393 2007-02-02 14:03 config.php
[...]


In particular make sure that you:

  • change the database connection parameter
  • make sure the MySQL database configured with RB_DB_DB exists
  • update the list of binaries in the hash $rb_binaries

Finally, you can try to run one of the micro-benchmarks. Here is my attempt to start it. It ends in an error, because I have not started the configures MySQL Server to store the runtimes yet. However, this failure is very good for educational purpose, because it shows you what the script does and how to debug. The script tries to execute a copy of the micro-benchmark (mysqli_connect_php_run_normal.php). You can run and debug this file like any other standalone PHP script. You can see the exact call what the framework does to run this script. When you found the cause of the failure, you must manually remove it before you rerun the framework.

nixnutz@linux-eu6p:~/blog/php6_mysqlnd/ext/mysqli/tests/bench/framework> ~/blog/php6_mysqlnd/sapi/cli/php main.php -v ../micro_benches/mysqli_connect.php

[2007-02-02 16:16:08] Starting run for binary 'libmysql' and runner 'rb_testrunner_normal'...
  ... running file '/home/nixnutz/blog/php6_mysqlnd/ext/mysqli/tests/bench/micro_benches/mysqli_connect.php'
  ...'/home/nixnutz/blog/php6_libmysql/sapi/cli/php -f 
/home/nixnutz/blog/php6_mysqlnd/ext/mysqli/tests/bench/micro_benches/mysqli_connect_php_run_normal.php'
Errors during bench run: 'Connect TCP/IP success' failure [original code: yes]
'Connect Socket success' failure [original code: yes]


Syntax:
  program [options] dir_or_file [dir_or_file [dir_or_file ...]]

Options:
  -v                - Verbose
  -h                - Help
  -q                - Quiet, suppress output
  -p                - Profile with oprofile (see config.php)

I started the configured MySQL Server, removed the temporary file and rerun the main.php

ixnutz@linux-eu6p:~/blog/php6_mysqlnd/ext/mysqli/tests/bench/framework> rm ../micro_benches/*run_normal*
nixnutz@linux-eu6p:~/blog/php6_mysqlnd/ext/mysqli/tests/bench/framework> ~/blog/php6_mysqlnd/sapi/cli/php main.php -v ../micro_benches/mysqli_connect.php

[2007-02-02 16:23:43] Starting run for binary 'libmysql' and runner 'rb_testrunner_normal'...
  ... running file '/home/nixnutz/blog/php6_mysqlnd/ext/mysqli/tests/bench/micro_benches/mysqli_connect.php'
  ...'/home/nixnutz/blog/php6_libmysql/sapi/cli/php -f 
/home/nixnutz/blog/php6_mysqlnd/ext/mysqli/tests/bench/micro_benches/mysqli_connect_php_run_normal.php'
[...] 
                                         libmysql          mysqlnd
---------------------------------------------------------------------------
Connect TCP/IP success                   2.3604s ( 100%)  2.6366s ( 111%)
Connect Socket success                   2.2580s ( 100%)  3.0613s ( 135%)
Connect Socket failure                   1.9615s ( 100%)  2.0672s ( 105%)
Connect TCP/IP failure                   1.9193s ( 100%)  1.8259s (  95%)
===========================================================================
Total                                    8.4991s ( 100%)  9.5910s ( 112%)
---------------------------------------------------------------------------

No error, mysqlnd is about 10% slower for mysqli_connect(). However, this is the first alpha release and for the
Dell DVD Store we already beat libmysql, although we are slower here!

nixnutz@linux-eu6p:~/blog/php6_mysqlnd/ext/mysqli/tests/bench/framework> ls -la web/
insgesamt 284
drwxr-xr-x 2 nixnutz users   200 2007-02-02 16:24 .
drwxr-xr-x 4 nixnutz users   336 2007-02-02 16:24 ..
-rw-r--r-- 1 nixnutz users 62022 2007-02-02 16:24 index.html
-rw-r--r-- 1 nixnutz users 63109 2007-02-02 16:24 index_wiki.txt
-rw-r--r-- 1 nixnutz users 77022 2007-02-02 16:24 mysqli_connect_php.html
-rw-r--r-- 1 nixnutz users 78143 2007-02-02 16:24 mysqli_connect_php_wiki.txt

How does the micro-benchmarking work?

The basic idea of these micro-benchmarks is to have a several PHP binaries executing the same script on the command line. The script is plain-vanilla PHP. It provides two hashes $errors and $times which the caller of the script can use to generate some human-readable output. Times are recorded using microtime(true).There is no web server involved and as few overhead as possible to make low-level debugging with oprofile, valgrind, callgrind, ddd, strace and whatever else development tool as simple as possible.

The scripts in the directory micro_benches look like this. It should be easy for everybody to add their own micro-benchmarks:

$times = $errors = array();
$runs = 20000;

do {
  $times['overall'] = microtime(true);

  if (!$mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket)) {
    $errors[] = sprintf("Cannot connect: [%d] %s\n", 
       mysqli_connect_errno(), mysqli_connect_error());
    break;
  }
 [...]
}

The framework loops over the configured PHP binaries and does for every PHP binary it finds: php -f micro_benchmark_php_run_normal.php . With micro_benchmark_php_run_normal.php beeing:

$db = ;
[...]
include('micro_benchmark.php');
[...]
$fp = fopen('data_exchange_file_for_caller', 'w');
fwrite($fp, serialize(array('errors' => $errors, 'times' => $times));
fclose($fp)

The framwork opens the file ‘data_exchange_file_for_called’ reads the hashes $errors and $times, decides what to do and might eventually present you the results in a human-readable way. Currently the framework is over-modularized. However, the idea is to have one fine day more “runners” that do “strace -tt php -f micro_bench.php” and pre-process the output for system call bottleneck-analysis or use oprofile for CPU time analysis.

What do the figures mean?

The meaning of the labels or figures like “Connect TCP/IP success” of a micro-benchmark depends on the PHP script used. You do not know what it means and tries to measure, before you look it up in the source of the micro-benchmark. In this case the answer is in “mysqli_connect.php”. Note that labels can be totally misleading. You need to look carefully at the script. This is why the entire source code of the script is part of the generated HTML output.

It is a hacker’s tool!

Benchmarking and bottle-neck analysis is difficult. You need to be a bit of a hacker. And the first figures we present about mysqlnd are figures for hackers. At this point the message to you is: we believe to have made already the alpha faster than libmysql in many cases, but check yourself. And help us to further improve performance and stability. php@lists.mysql.com is the preferred way to contact us.

2007/02/02
by admin
2 Comments

MySQL native driver for PHP: mysqlnd-5.0.0-alpha

Dear Developers,

we are proud to announce the first alpha version of the MySQL native driver for PHP: mysqlnd 5.0.0-alpha. The software is available for download on http://dev.mysql.com/downloads/connector/php-mysqlnd.

The MySQL native driver for PHP is an additional, alternative way to connect from PHP 6 to the MySQL Server 4.1 or newer. It is a replacement for libmysql, the MySQL Client Library. From now on you can use ext/mysqli either together with libmysql as you did in the past or with mysqlnd. The MySQL native driver for PHP requires PHP 6 and can connect to MySQL Servers 4.1 or newer.

We have no plans to remove libmysql support from ext/mysqli, which would break existing applications. We just add a superior alternative to our PHP offerings:

  • The new development is licensed under the terms of the PHP license to solve any license issues.
  • On the C-level, mysqlnd uses many of the proven and stable PHP internal functions.
  • All the code is contained in the ext/mysqli source directory. There is no longer a need to link any external libraries. Thus you neither
    need to install the MySQL client library to compile PHP with MySQL support nor do you need to take care of versions.
  • Compiling has been made easier.
  • The performance of some functions has been improved. We have measured considerable performance improvements, for example when
    fetching buffered result sets.

Features and Limitations

This first alpha release is not feature complete. From the API additions discussed in November 2006, we managed to implement a first version of:

  • persistent connections
  • mysqli_fetch_all()
  • a first performance statistics call: mysqli_get_cache_stats()

Others will follow.

Unfortunately this alpha does not include Prepared Statement support. Support for Prepared Statements is our next development goal.

Closed and open development

With this alpha release we have laid the foundation for future work. We had to implement very technical and, from a user perspective, boring things like the MySQL communication protocol. We did this in a rather “closed” way. But now that the first functions are visible we have more interesting things to share than network protocol functions.

Please contribute to the development on the mailing list php@lists.mysql.com and share your ideas. See http://lists.mysql.com for details how to subscribe to the list.

As soon as the driver is feature complete and stable, we will merge it into the PHP CVS on http://cvs.php.net.

Getting the software and Installation

Please check the download page on http://dev.mysql.com/downloads/connector/php-mysqlnd for instructions.

2007/01/18
by admin
Comments Off on Webseminar: Web-2.0-Anwendungen absichern

Webseminar: Web-2.0-Anwendungen absichern

Es gibt Angebote des Arbeitgebers, die man nur mit gemischten Gefühlen bewirbt. Und es gibt solche, die man bedenkenlos empfehlen kann. Wenn Johann-Peter Hartmann sich anschickt ein Webseminar zum Thema Web-2.0-Anwendungen absichern zu geben, dann ist das ein Pflichttermin.

Ich hatte das Glück in den letzten Jahren immer mal wieder mit Johann arbeiten zu dürfen und hoffe darauf, dass dies auch in Zukunft so sein wird, weshalb ich dieses Webseminar guten Gewissens empfehlen kann. Die Beweihräucherung seines PHP-Konferenz Talks von Andreas Demmer trifft es bereits sehr gut. Ich würde noch einen Schritt weiter gehen und ihn als Günter Jauch der deutschen PHP-Szene bezeichnen: er hat eine hervorragende Redaktion um sich versammelt und versteht es die von der Redaktion gewonnenen Erkenntnisse in perfektes Infotainment umzusetzen. Eloquent präsentiert er die technischen Details in einer dem Publikum angemessenen Art und Weise. Massentauglich, für Anfänger wie Experten geeignet, präsentiert er aktuelle Lösungsansätze und hinterfragt diese gekonnt. Da er bei diesem Webseminar nicht gezwungen ist, englisch zu sprechen, kann er anders als beim letzten Webseminar seinen Wortwitz voll ausspielen.

Ich kenne viele brilliante Techniker. Einige übertreffen das technische Wissen von Johann, aber nur die allerwenigsten können das verinnerlichte Wissen auch vermitteln. Und die, die gut als Lehrer sind, sind nicht immer die besten Hacker mit den neuesten Informationen. Ich erhoffe mir von dem Webseminar eine Mischung aus beiden Welten auch auf die Gefahr hin die Messlatte für einen 45-Minuten Vortrag sehr hoch zu legen, denn live ist er besser. Vielleicht sind die Erwartungen zu hoch nach dieser ultimativen Lobdudelei, aber so wie “Zimmer frei!”, einen Stammplatz in meinem TV-Programm hat, ist dies ein Anwärter auf einen Stammplatz in meinem Infotainment-Programm. Und dies ist eine der wenigen Empfehlungen, die ich gerne ausspreche.

Mein persönliches Infotainment-Programm – wenn ich schon nicht täglich mit ihm arbeite – sieht am Donnerstag, 30. Januar 2007, 14:00 MEZ eine Unterbrechung des australischen Radioprogramms vor, um an dem Webseminar teilzunehmen. Um Anmeldung wird gebeten. Wer den Termin nicht wahrnehmen kann, kann – wie üblich – kurze Zeit nach dem Seminar eine Aufzeichnung herunterladen.

Aus dem Inhalt


Die verbesserte Einsatztauglichkeit der Web-2.0-Anwendungen wird auf Kosten von neuen Sicherheitsproblemen erworben. Sowohl die mächtige Logik im JavaScript als auch der permanente Login auf vielen Sites bergen Risiken, die anders und gezielt beantwortet werden müssen. Dieses Webseminar gibt einen Überblick, bewertet die Probleme und stellt Lösungswege vor.


Wenn Sie Web 2.0- und AJAX-Anwendungen entwickeln, ist dieser Vortrag genau das Richtige für Sie! Hier erfahren Sie:

  • Welche neuen Sicherheitsrisiken es für Webanwendungen gibt
  • Welche Bedeutung XXS hat
  • Ursprünge und Typen von JavaScript-Malware
  • Wege zur Absicherung Ihrer LAMP-Anwendungen für Web 2.0

P.S.: 45 Minuten sind arg wenig um Wissen zu vermitteln. Aber ich erwarte hier eine gut strukturierte, aktuelle Einführung in das Thema, die hörenswert ist, obwohl ich den Vortrag und die Kommentare der anderen Experten zum Thema noch nicht kenne.

2006/11/19
by admin
1 Comment

PHP 6: ext/mysql und ext/mysqli mit Unicode Unterstützung

Georg hat heute die Arbeiten zur Unicode Unterstützung von ext/mysql in PHP 6 abgeschlossen. Die Änderungen wurden vor wenigen Stunden dem PHP 6 CVS-Repository beigefügt. Damit unterstützen jetzt beide nativen APIs von MySQL (ext/mysql und ext/mysqli) die Unicode Fähigkeiten von PHP 6. Nicht ohne Stolz sei erwähnt, dass MySQL damit einer der ersten – wenn nicht sogar der erste -Datenbankhersteller ist, der PHP-Anwendern einen Ausblick auf den vollen Funktionsumfang von PHP 6 ermöglicht. Klasse Arbeit, Georg!

Wer mag, kann die Neuentwicklung in einer kleinen Umfrage kommentieren.

2006/11/13
by admin
Comments Off on Umfrage: mysqlnd – MySQL native driver für PHP

Umfrage: mysqlnd – MySQL native driver für PHP

Es ist Montag und wer noch nicht mit der Arbeit beginnen mag, kann sich hinter der Ausrede verstecken, eine Umfrage ausfüllen zu müssen:

Umfrage: mysqlnd – MySQL native driver für PHP

Es ist nicht lange her, daß Kaj den Plan verkündet hat, einen neuen nativen MySQL Treiber für PHP zu entwickeln. Der neue Treiber wird unter die PHP Lizenz gestellt werden. PHP intern ersetzt der neue Treiber die libmysql.

Für den Anwender und für bestehende PHP-Applikationen erfolgt die Änderung transparent. Es wird weder eine neue Extension entwickelt werden noch eine neue API für PHP-Programmierer eingeführt. Stattdessen wird “unter der Haube” von PHP, auf der C-Ebene, ein neuer Treiber für PHP 6 entwickelt werden, der als Alternative zur libmysql verwendet werden kann. Der Treiber kann bei der Kompilierung von PHP 6 als Ersatz für die libmysql in ext/mysqli und PDO/MySQL eingebunden werden.

Während der PHP-Konferenz in Frankfurt hat die Ideensammlung begonnen ob und wenn ja, welche neuen Funktionen der neue Treiber – mysqlnd (MySQL native driver for PHP) – unterstützen sollte. Lukas und ich berichteten bereits. Um die Wünsche der Anwender besser einschätzen zu können, haben wir eine kleine Umfrage erstellt. Es sollte nicht mehr als drei Minuten dauern die 10 Fragen auf drei Seiten zu beantworten. Die Fragen verraten nicht nur worüber nachgedacht wurde sondern bieten auch die Gelegenheit den Wochenbeginn noch einen kurzen Moment zu verzögern ;-).

Umfrage: mysqlnd – MySQL native driver für PHP

Rückmeldungen zu den Ideen – ob per Umfrage oder E-Mail – sind sehr willkommen. Noch ist nicht entschieden welche Funktionen implementiert werden und noch ist die Gelegenheit vorhanden eigene Wünsche zu formulieren.

2006/11/11
by admin
Comments Off on mysqlnd – MySQL native driver for PHP driver

mysqlnd – MySQL native driver for PHP driver

Not long ago, Kaj announced the plan to develop a native driver for PHP. As Kaj explained, the new development will be licensed under the terms of the PHP license and donated to the PHP Group to solve any license issues.

Don’t get us wrong here. We will not break any existing PHP code or PHP applications! We want to develop another, technical superior option for PHP users to connect to MySQL. Most of the new developments will happen “under the hood” of PHP on the C level. We will write a replacement for the libmysql that can be used by PHP extension internally. We will not develop a new PHP extension, thus there will be no new API for PHP developers. You will be offered an additional, alternative option in PHP 6 to connect to the MySQL Server.

Today
PHP API “under the hood of PHP” on the C level MySQL Server
ext/mysql -> libmysql -> MySQL Server
ext/mysqli -> libmysql -> MySQL Server
PDO/MySQL -> libmysql -> MySQL Server
PHP 6
ext/mysqli -> libmysql alternatively: mysqlnd -> MySQL Server
PDO/MySQL -> libmysql alternatively: mysqlnd -> MySQL Server

The new native driver will be tightly integrated into PHP and use the existing internal PHP infrastructure: Strings, Zend Memory Management, PHP Streams (Virtual I/O), Hashes, Lists Thread Safe Resource Manager, ZLIB, SSL, Crypt, …. Using these proven and stable C modules, the new driver should become much leaner. Plus: you do not need to link against an external library (libmysql) any more and you do not need to worry about library versions any more, because the code of mysqlnd will be part of PHP.

C modules used by the libmysql vs. mysqlnd
libmysql mysqlnd
MySQL STRINGS PHP String functions
MySQL MYSYS PHP/Zend Memory Management
MySQL VIO PHP Streams
ZLIB, SSL, Crypt All are part of PHP

So, what chance did we developers have but to meet during the International PHP Conference 2006 in Frankfurt and do some brainstorming about how it could be done? The conference was an excellent opportunity to meet and interview some of the PHP brains, for example Marcus, Sara and Stefan – to name just a few. I am really thankfull that the organizer made this conference possible and we have been given the opportunity to run our meetings during the conference.

The brainstorming was not only done by MySQL employees like Georg, Andrey, Hartmut and me but Lukas and Peter also joined the meeting and gave great input. We came up with some interesting ideas. Lukas blogged already about some of them. More details will follow in future blog postings.

No final decisions have been made so far which idea we will implement and which not. We are looking for more feedback from the Community before the development starts in about one week. It would be great if you could fill out the following short survey. It won’t take you more than three minutes to answer the ten questions spreaded over three pages. Also, the questions give you hints what we are considering to implement, just in case you are curious …

If you have ideas about what should go into mysqlnd or you have any worries, never hesitate to contact Georg, Andrey or me directly. We appreciate all feedback from you that we can get.

Further blog postings about our work will follow. We will try to write one or two blog postings per week. Sometimes, we might just summarize the development work. Sometimes we might explain in more detail about the ideas and ask you again for feedback using a survey. Stay tuned and happy hacking!

2006/10/31
by admin
1 Comment

MaxDB: Standby Databases

Every time I try, I fail. I always fail to set up a MaxDB standby database using the Database Manager GUI. It is neither very complicated to set up a standby system nor do the wizards look very different every time I try it. Nevertheless, I manage to fail all the time. As an reminder for myself and as a tutorial for all MaxDB beginners, I decided to write it down. Step by step and with lots of screenshots.

MaxDB High Availability

MaxDB offers a great number of high availability options: Backup and Recovery, (Database) Snapshots, Using copied Snapshots or Split Mirror for data backup, Cluster for Failover, Shadow database (standby database) and Hot Standby. Check the MaxDB manual for the details.

Backup and Recovery has been available in MaxDB since ever. It supports pretty much everything that one can ask for: parallel backup media for performance reasons, automatic log backup, incremental data backup, support of major third party backup solutions, and, and, and … Database snapshots are a fast and efficient way to freeze the status of a database and to recover the snapshot very fast.

Modern storage systems and some operating system level solutions allow the creation of consistent snapshots of file systems and disks while applications are writing data to the disks. The creation and recovery of a snapshot is usually very fast, much faster than reading all records from the database and transferring them to an external backup medium. The data and log volumes of MaxDB can be backed up and duplicated this way to set up standby systems on which resource consuming tasks can be run, e.g. structural integrity tests or backup operations.

Using a shared disk approach you can integrate MaxDB in Cluster solutions. If a MaxDB server crashes for whatever reason, the cluster client can take care of the application switch over and start a Standby MaxDB server in the Cluster which runs on the same volumes as the crashed MaxDB server.

MaxDB Hot Standby is one variant of such a shared disk approach which reduces the number of single points of failures (data area and log area) down to one (log area) using very secure, specialized hardware. In a Hot Standby setup several MaxDB database instances run each on their own data area but share the log area. One Master database instance is online and writes to the log area while a standby system reads the recently written entries from the log area. If the master fails, the standby system has to repeat a few log entries in the worst case before it can be switched in online mode. Usually, the replay of the log entries will take much less time than it takes to redirect the application clients. That means that the switch will be transparent to the user.

Continue Reading →

2006/10/17
by admin
Comments Off on SERVER_QUERY_NO_INDEX_USED, SERVER_QUERY_NO_GOOD_INDEX_USED

SERVER_QUERY_NO_INDEX_USED, SERVER_QUERY_NO_GOOD_INDEX_USED

Die MySQL-Server Optionen --log-slow-queries und --log-queries-using-no-indexes sollten jedem MySQL-Anwender geläufig sein. Wenn nicht, schnell die Links verfolgen und die Wissenslücke schließen.

Nicht bekannt waren mir die Flags SERVER_QUERY_NO_INDEX_USED und SERVER_QUERY_NO_GOOD_INDEX_USED. Ich bin das erste Mal über die beiden Flags gestolpert als ich mich fragte wie ein Test für die PHP-Funktion mysqli_report() auszusehen hat. mysqli_report() ist eine überaus nützliche Funktion, welche die ansonsten wenig redsame ext/mysqli-API dazu bringt jedes noch so kleine Problem in Form einer PHP-Warning oder eines PHP-Errors anzuzeigen. Gerade auf Test- und Entwicklungssystemen ist die nützlich, um Probleme aufzudecken, die ansonsten nicht einmal ein error_reporting(E_ALL) zu Tage fördert. Ich kann nur dazu raten, die Funktion auszuprobieren, sofern diese nicht ohnehin schon im Einsatz ist.

Wenn man einen Test für eine API-Funktion schreiben will, dann kann man sich entweder auf die Korrektheit und Vollständigkeit der Dokumentation verlassen und das dort spezifizierte im Test validieren oder aber man betrachtet die Kommentare zur Funktion. Ich habe etwas in den Kommentardateien mit der Endung *.c geblättert und da war es dann:

...
if (status & SERVER_QUERY_NO_GOOD_INDEX_USED) {
...
if (status & SERVER_QUERY_NO_INDEX_USED) {
...

Continue Reading →

2006/10/05
by admin
Comments Off on Von nichts eine Ahnung

Von nichts eine Ahnung

An manchen Tagen fühle ich mich, als hätte ich von nichts eine Ahnung. So richtig enden will der Umzug noch nicht, da rollt schon die nächste Baustelle auf mich zu: MySQL. In jüngster Zeit komme ich immer mal wieder mit MySQL in Kontakt. MySQL benutzen ist etwas, was ich jetzt seit Jahren nicht mehr getan habe und so manches Detail muß ich mir erst wieder mühsam erarbeiten.

Baerli hatte mir einen Artikel reingedrückt zu MySQL Security. Klar: das kann man vor der Glotze schreiben, GRANT, CREATE USER, DROP USER, SET PASSWORD runterbeten und gut ist. Aber das wollte ich nicht. Also las ich mir ein paar Handbuchseiten durch. Heja, ich habe ja von nichts eine Ahnung…

RENAME

Als erstes stolperte ich über RENAME. MySQL bindet Zugriffsrechte nicht an konkrete SQL-Objekte, sondern an irgendwelche SQL-Objekte, die einen bestimmten Namen haben. MaxDB bindet ein Recht nicht an den Namen sondern an das SQL-Objekt selbst. Wenn man einem MySQL-Anwender Zugriff auf eine Tabelle “mytable” gibt, dann hat er nach einem RENAME TABLE mytable _mytable keinen Zugriff mehr auf das konkrete Objekt, welches seinen Namen von “mytable” auf “_mytable” gewechselt hat. Unter MaxDB hat der Anwender nun Zugriff auf die Tabelle “_mytable”, das Recht wurde transparent übertragen.

Legt man nun unter MySQL eine neue Tabelle “mytable” an, dann hat der Anwender wieder Zugriff auf die neue Tabelle. MaxDB hingegen erkennt, daß es sich um ein anderes Objekt handelt und sperrt den Zugriff.

So einfach und charmant die MySQL-Lösung ist Rechte für Objekte zu vergeben, die einem Namenspattern entsprechen so seltsam ist die Vorstellung, dass jemand mit der Umbenennung von Schemata groben Unfug treiben könnte. Ich empfinde den MaxDB-Weg nach kurzer Eingewöhnung als konsequenter. Aber man gewöhnt sich wohl an alles.

NO_AUTO_CREATE_USER

Wenn ich in der Vergangenheit den Kopf über MaxDB geschüttet habe und genörgelt habe, daß Dinge “halbgar” erscheinen, dann gibt das auch für den SQL-Mode NO_AUTO_CREATE_USER unter MySQL. Der Modus sorgt dafür, dass GRANT keine User anlegt sofern diese kein Passwort mittels IDENTIFIED BY zugewiesen bekommen. Das klang für mich wie eine schlaue Idee, die Cron-Jobs mit SELECT user, host FROM user WHERE password = ” überflüssig machen könnte. Doch meine Hoffnungen wurden arg enttäuscht. Das was ich mir wünschte müsse ja “NO_EMPTY_PASSWORD” heißen und habe nun überhaupt nichts mit NO_AUTO_CREATE_USER zu tun. NO_AUTO_CREATE_USER ist einzig und allein ein “Bugfix” und “Komfortfeature” für GRANT. GRANT gab es vor CREATE USER. Deshalb konnte GRANT dazu benutzt werden User anzulegen auch wenn das vielleicht nicht ganz im Sinne des Wortes “to grant” sein mag. Falls man sich nun bei der Benutzerverwaltung vertippt, dann ist schnell versehentlich ein neuer Benutzer ohne Passwort angelegt anstatt die Rechte eines bestehenden Benutzers zu ändern. Das kann passieren, weil GRANT nicht “to grant” macht sondern mehr macht. Statt nun das GRANT eine Fehlermeldung ausgeben zu lassen, daß man CREATE USER benutzen solle, wurde aufgrund von Abwärtskompatibilität ein Schutz durch die Hintertür eingefügt. GRANT schlägt fehl, wenn der Benutzername unbekannt ist (möglicher Tippfehler) und kein IDENTIFIED BY (oft nicht der Fall bei einfachen GRANT Anweisungen) angegeben ist, sofern NO_AUTO_CREATE_USER gesetzt ist.

Warum GRANT nicht nörgeln kann und auf CREATE USER verweist und kein weiteres Flag NO_EMPTY_PASSWORD eingeführt wurde… Naja, es wird eine Diskussion gegeben haben und leider haben die Leute es bislang immer geschafft mit micht guten Argumenten zu überstimmen, aber schön finden. Aber man gewöhnt sich wohl an alles.

Zwei MySQL-Server auf einem Datenverzeichnis

–skip-privileges ist ein Segen und ein Fluch. Ich empfinde es als Segen. Root-Passwort vergessen? Kein Problem: Datenbank ohne Benutzerprüfungen starten. Nun kann man das natürlich auch als Risiko ansehen, besonders dann wenn jemand Zugriff auf das Binary des Deamon und das Datenverzeichnis hat.

Was hindert mich eigentlich daran einen zweiten MySQL-Server mit dem gleichen Datenverzeichnis zu starten, die Passworte zu verfummeln während der erste MySQL-Server läuft und dann wieder den zweiten MySQL-Server zu stoppen? Etwas kompliziert gedacht, aber so bin ich nun mal. Und natürlich, MyISAM läuft in die Falle. InnoDB erkennt, daß bereits ein Server an den Daten- und Logfiles spielt, aber mit einem –skip-innodb startet der zweite Server und die Änderungen an der MyISAM Datenbank “mysql” gehen schnell von der Hand. Schnell die Accounts verdrehen, zweiten Server stoppen und warten bis der erste Server ein FLUSH PRIVILEGES ausführt.

Ok, die Passworte kann man schnell wieder richten, aber zwei Prozesse auf den gleichen Dateien? MaxDB nörgelt wenigsten rum, wenn man solchen Unsinn versucht. Aber man gewöhnt sich wohl an alles.

… und irgendwann werde ich dann auch verstehen wieso die Dinge so funktionieren wie sie funktionieren. Im ersten Moment ist alles fremd. Wo ist eigentlich die Küche in dieser fremden Wohnung?