Ulf Wendel

2009/10/16
by admin
0 comments

PHP: 150 performance tuning screws for mysqlnd

Yes, 150 means we added some 30 performance statistics to the MySQL native driver for PHP (mysqlnd) since monday. The new statistics are explained in three words: counting COM_* commands. COM_* commands refers to the command packets of the MySQL client server protocol. For example, COM_QUERY is used to execute nonprepared SQL statements.

Please check the earlier blog postings on how to use and access the statistics: PHP: 59 tuning screws for mysqlnd, PHP: 120 tuning screws for mysqlnd. The information given in those articles will find its way into the PHP and MySQL manual. The MySQL documentation team is working on an update. But for now, an hour after the latest commit, you are requested to check the blog postings.

Continue Reading →

2009/10/13
by admin
0 comments

Warum ich ext/mysql mag…

Es gibt drei Extensions mit deren Hilfe ein PHP-Skript auf einen MySQL Server zugreifen kann: ext/mysql, ext/mysqli und PDO_MYSQL. Alle drei sind geeignet, um die Entwicklungsgeschichte von PHP und MySQL Revue passieren zu lassen, alle drei sind geeignet, um Kopfschütteln oder Staunen hervorzurufen. Heute: Grundlagen des Verbindungsaufbaus mit ext/mysql – wie verbinde ich PHP mit MySQL?

Was wird folgendes Kommando ausgeben?

time MYSQL_TCP_PORT=3307 sapi/cli/php -r '$link = mysql_connect("127.0.0.1", "root", "root"); mysql_query("SELECT SLEEP(10)"); var_dump($link);' 

Um zu beantworten was passieren wird, ist es notwendig das Betriebssystem, die verwendete Client Bibliothek und mindestens eine PHP-Konfigurationsdirektive zu kennen. Das Betriebssystem ergibt sich aus dem Beispiel: es ist ein Unix. Die verwendete Client Bibliothek ist MySQL Client Library (libmysql). Es ist ein Standardbuild, genauso wie PHP und MySQL unverändert aus der Tüte gefallen sind. Es wurden keine PHP-Konfigurationsdirektiven gesetzt und die Standardeinstellungen von PHP 5.3 werden benutzt.

Das Betriebssystem und die PHP-Konfigurationsdirektive mysql.default_port entscheidet darüber ob das Setzen der Umgebungsvariablen MYSQL_TCP_PORT einen Einfluß auf ext/mysql hat. Unter Windows oder Netware wird die Umgebungsvariable nicht ausgewertet. Im Beispiel wird ein Unix verwendet. Auf diesem System wird die Umgebungsvariable einen etwaigen “mysql” Eintrag aus der TCP-Sektion in /etc/services überstimmen, sofern kein Wert für mysql.default_port gesetzt ist, welches die Standardeinstellung ist. Ist das dokumentiert? Ja, in der php.ini-production findet sich eine Notiz. Dort wird auch die Bedeutung des Compile-Flags MYSQL_PORT erklärt.

Da als Hostname die IP-Adresse “127.0.0.1” angegeben ist und der Port 3307 benutzt wird gemäß der Umgebungsvariable MYSQL_TCP_PORT, baut die MySQL Client Library (libmysql) eine TCP/IP Verbindung auf. Die Verbindung schlägt fehl, weil es sich beim MySQL Server um eine Standardinstallation handelt, die auf Port 3306 horcht. Der Fehler führt zu einer PHP Warnung die, je nach Wert der PHP-Direktive error_reporting, leicht übersehen werden kann: Warning: mysql_connect(): Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in Command line code on line 1.

Anschließend macht PHP unbeirrt weiter und der Aufruf von mysql_query() baut implizit eine neue Verbindung auf, weil – wie bei ext/mysql üblich und möglich – kein Handle angegeben wurde. Ja, das ist dokumentiert. Die Verbindung wird zum Host = NULL auf Port 3307 aufgebaut. Host = NULL findet Anwendung, weil kein Wert für die PHP-Konfigurationsdirektive mysql.default_host gesetzt ist. Eine leere Hostangabe bewirkt unter Unix in der MySQL Client Bibliothek einen Fallback auf localhost und Unix Domain Sockets. Auf Windows würde etwas anderes passieren.

Mit der Hostangabe localhost und mit dem Standardwert einer leeren PHP-Konfigurationsdirektive mysql.default_socket wird das Socket /tmp/mysql.sock verwendet. Aber auch nur, wenn es sich um einen Standardbuild von PHP handelt, PHP_MYSQL_UNIX_SOCK_ADDR nicht beim Kompilieren definiert wurde und es sich auch um einen Standardbuild der MySQL Client Library handelt. Ist das dokumentiert? Sicher, ich habe es doch hiermit gerade dokumentiert!

Schlußendlich gelingt es SELECT SLEEP(10) über einer Unix Domain Socket Verbindung an MySQL zu senden und das Skript wird nach etwa 10 Sekunden beendet. var_dump($link) gibt false aus, da der Verbindungsaufbau fehlgeschlagen ist. Hier noch einmal das korrekte und fehlerfreie Ergebnis im Ãœberblick:

time MYSQL_TCP_PORT=3307 sapi/cli/php -r '$link = mysql_connect("127.0.0.1", "root", "root"); mysql_query("SELECT SLEEP(10)"); var_dump($link);'          

Warning: mysql_connect(): Lost connection to MySQL server at 'reading initial communication packet', system error: 111 in Command line code on line 1
bool(false)

real    0m10.024s
user    0m0.008s
sys     0m0.004s

Alles gaaanz easy…. Und bloß nicht ext/mysqli verwenden. Das baut nicht implizit Verbindungen auf, unterbindet die Verwendung von Umgebungsvariablen, verhindert das Bauen von optimierten und angepassten Binaries mit verbesserten Standardeinstellungen, verlangt bei jedem Kommando die Angabe eines Verbindungshandle und unterstützt neben irrelevanten Dingen wie Prepared Statements auch noch performanzkritische C API Funktionen wie mysql_warning_count().

2009/10/12
by admin
2 Comments

PHP: 120 tuning screws for mysqlnd

The MySQL native driver for PHP (mysqlnd) is capable of collecting some 120 performance statistics. This is about twice as much as it was when I blogged about the 59 tuning screws for mysqlnd. While the basics have not not changed and the API calls for accessing the data remained the same (see previous posting) the new figures have never been described before.

The figures are for those of you who want to squeeze the last out of the PHP. Many of the statistics have been written for those who have developed mysqlnd and not for PHP users. The data is certainly still of interest for PHP experts but let me stress out again that it is for experts.

Continue Reading →

2009/09/14
by admin
0 comments

PHP Unconference 2009 – ist perfekt langweilig?

"Sie organisieren das hobbymäßig?" erkundigt sich ungläubig die Organisation einer im gleichen Gebäude stattfindenden Konferenz. Nicht ohne Stolz und völlig zu Recht macht die Frage die Runde. Die Runde besteht aus 220 Teilnehmern der PHP Unconference 2009 (Hamburg, 12.-13.09) deren untenstehenden Rückmeldungen und Kommentare das Erstaunen erklären (weitere Fotos).

DSC08531DSC08530DSC08529

Die PHP-Anwendergruppe Hamburg übertrifft mit der dritten Auflage der "Unconference" ihre Erfolge von den Vorjahren. Dank zahlreicher Sponsoren (Soprado, Mayflower, Microsoft, MySQL) und Supporter (Beasts Associated, O’Reilly, SinnerSchrader, Addison-Wesley) konnte das Geomatikum der Universität Hamburg angemietet werden und die Teilnehmer angemessen verpflegt werden. Nirgendwo sonst kann man für 25 Euro das Wer-ist-Wer der deutschsprachigen PHP-Szene zwei Tage lang treffen. Die PHP Unconference in Hamburg bleibt ein Muß für PHP- und MySQL-Anwender.

DSC08422

Unconf?

Auf der PHP "Unconf" bestimmt das Volk der Teilnehmer die Inhalte. Anders als bei einer Konferenz bestimmt nicht eine Gruppe von honorierten Wahlmännern, ein Programmkomitee, welches Thema vorgetragen wird. In einer morgendlichen Versammlung entscheiden die Teilnehmer welche der zuvor auf einer Webseite gesammelten Veranstaltungsthemen in einem großzügigen Hörsaal besprochen werden. Welche Form der Interaktion gewählt wird – Diskussion, Schulung, Vortrag, … -, um ein Thema zu bearbeiten ist der Gruppe überlassen. Es gibt nur zwei Regeln: nach Ablauf von 45 Minuten erfolgt ein striktes Ende und durch die Direktheit einer Unconference ist passiver Konsum fehl am Platze. Dieses Konzept funktioniert sehr gut wie Skeptiker am Tagesprogramm vom Samstag ablesen können.

DSC08427

Pausen und die Protokollierung der Veranstaltung nehmen einen breiten Raum im Gesamtkonzept ein, um den Austausch der Teilnehmer in den Vordergrund zu stellen.

DSC08456

Wie schon in den Vorjahren blieben die Teilnehmer auch abends zusammen, was weiteren Raum zum Erfahrungsaustausch bietet. Abends versammelte sich ein PHPmob zum PHProst an einem Treffpunkt nahe der Partymeile an der Sankt Pauli Hafenstraße. Eine tolle Idee! Wer wollte konnte sich in kleineren privaten Gruppen in einem der zahlreichen Restaurants zum Abendessen verabreden, um im Anschluß zum PHPmob zu gehen. Nachtschwärmer beendeten den Erfahrungsaustausch auf der nahegelegenen Reeperbahn, deren Lichter magische Anziehungskräfte auswirkten.

2010 die Meisterprüfung?

Im dritten Lehrjahr haben die Eventmanager vom OrgaTeam (Judith Andresen , Florian Blasel, Ekkehard Dörre, Jonathan Maron, Stefan J. Morgenroth, Hinrich Sager, Edouard Simon, Tobias Struckmeier, Markus Wolff) eine hervorragende Gesellenarbeit abgeliefert. Ich bin gespannt auf die Meisterprüfung in 2010. Darf man auf der PHP Unconference 2010 die Detailverliebtheit von Darren Cooper (PHP UG Frankfurt und mehr!) erwarten, der Community-Events mit einem gesponsorten Begrüßungscocktail perfektioniert? Inhaltlich sehe ich wenig Verbesserungspotential und hoffe dennoch nächstes Jahr wieder positiv überrascht zu werden.

2009/09/11
by admin
0 comments

The big POINTS in life

How large can a column of the data type POINT be: 10 bytes, 100 bytes, 1k, 10k? No… think Enterprise! PHP will allocate 4GB of RAM if you use the Prepared Statements of ext/mysqli and the MySQL Client Library (AKA libmysql) to fetch a POINT column. Of course, the MySQL native driver for PHP (mysqlnd) does better!

To understand why ext/mysqli can allocate up to 4 GB of RAM to fetch a POINT column we need to have a look at the MySQL C API. PHP itself is written in C and in a way ext/mysqli is just a plain vanilla C API client application. The C API is provided by the MySQL Client Library which has been called "libmysql" in the past. The MySQL Client Library implements the MySQL Client Server Protocol. The MySQL native driver for PHP (mysqlnd) is an alternative implementation of the MySQL Client Server Protocol and it is part of PHP source code as of PHP 5.3. If that is a new to you, please have a look at the PHP manual.

Continue Reading →

2009/09/10
by admin
0 comments

MySQL Connector for OpenOffice.org is GA

The first production version of the MySQL Connector for OpenOffice.org has been released. You can download it from http://extensions.services.openoffice.org/project/mysql_connector. The driver is implemented as an OpenOffice.org extension and thus it is very easy to install. The driver can be used in OpenOffice.org 3.1.1 and the upcoming OpenOffice.org 3.2 to connect to MySQL 5.1 or newer. Installation and first steps are described on http://wiki.services.openoffice.org/wiki/Database/Drivers/MySQL_Native/1.0.

Continue Reading →

2009/09/07
by admin
Comments Off on Connector/C++: 1.1.0 uses Boost

Connector/C++: 1.1.0 uses Boost

Andrey mentioned it long ago: MySQL Connector/C++ 1.1.0 makes use of some Boost components. The change impacts those who compile the MySQL driver for C++ from source. You need to have Boost 1.34.0 or newer installed on your build system. Users of a binary distribution do not need to take any action. Boost is not required when using the pre-compiled binaries. Nor is Boost needed to run client applications that make use of Connector/C++.

Boost is a highly regarded cross-platform library for C++ development used by many projects, for example OpenOffice.org. Some parts of Boost are included in the C++ Standards Committee’s Library Technical Report (TR1) and will be in the new C++0x Standard. Several other parts are either additions to TR1 or proposed for TR2. Boost is licensed under the terms of the Boost Software License which allows both commercial and non-commercial use.

Connector/C++ 1.1.0 uses a couple of "headers only" components. Among them the Any and Variant datatypes and some useful (smart|auto) pointers. They are all implemented as templates. Therefore you do not need to have any Boost binaries installed for building the driver nor does the driver link any binaries from Boost. You just need to have some Boost header files available for the build.

Continue Reading →

2009/09/04
by admin
Comments Off on Connector/C++: 1.1.0 offers run-time dynamic linking of libmysql

Connector/C++: 1.1.0 offers run-time dynamic linking of libmysql

From 1.1.0 on, Connector/C++ can optionally use run-time dynamic linking to access the MySQL Client Library (AKA libmysql). If you make use of this new feature, it will not only change the application binary interface (ABI) but also has some impact on your client applications. The new expert setting is not enabled by default. By default, you will not notice any differences.

The next version of MySQL Connector/C++ will be numbered 1.1.0. 1.1.0 marks the successful end of the first year of development. The driver finally offers everything needed by its two "internal customers". Also, feedback from MySQL Workbench and Connector/OpenOffice.org and the bug inflow demonstrated the maturity that has been reached making it a logical step to bump up the version number.

While MySQL Workbench has been happy with the feature set for a while, we implemented a couple of changes in 1.1.0 to also please Connector/OpenOffice.org. The biggest change is on how MySQL Connector/C++ can load the MySQL Client Library to connect to the MySQL Server. As you may know, the MySQL driver for C++ does not implement the MySQL Client-Server Protocol itself. Instead the driver wraps and uses the MySQL Client Library, the C-API, to talk to the MySQL Server. From version 1.0.0 to 1.0.5 the driver has just linked the MySQL Client Library at compile time. But from 1.1.0 on you can either link the MySQL Client Library at compile time, which remains the "safe" and proven default, or you can instruct the driver to use run-time dynamic linking (dlopen() resp. LoadLibrary()) to load the library.

Continue Reading →