<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="/blog/templates/default/atom.css" type="text/css" ?>

<feed 
   xmlns="http://www.w3.org/2005/Atom"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/">
    
    <link href="http://schlueters.de/blog/feeds/atom10.xml" rel="self" title="Johannes Schlüter" type="application/atom+xml" />
    <link href="http://schlueters.de/blog/"                        rel="alternate"    title="Johannes Schlüter" type="text/html" />
    <link href="http://schlueters.de/blog/rss.php?version=2.0"     rel="alternate"    title="Johannes Schlüter" type="application/rss+xml" />
    <title type="html">Johannes Schlüter</title>
    <subtitle type="html">Always searching for Life, the Universe and Everything</subtitle>
    <icon>http://schlueters.de/blog/templates/default/img/s9y_banner_small.png</icon>
    <id>http://schlueters.de/blog/</id>
    <updated>2012-04-04T09:33:16Z</updated>
    <generator uri="http://www.s9y.org/" version="1.5.5">Serendipity 1.5.5 - http://www.s9y.org/</generator>
    <dc:language>en</dc:language>

    <entry>
        <link href="http://schlueters.de/blog/archives/168-Quick-setup-for-PHP-development-trees.html" rel="alternate" title="Quick setup for PHP development trees" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2012-04-04T09:33:16Z</published>
        <updated>2012-04-04T09:33:16Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=168</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=168</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/168-guid.html</id>
        <title type="html">Quick setup for PHP development trees</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>As PHP has moved to git recently everybody who works on the PHP source has to recreate his work environment. When working on PHP I have a few <em>requirements</em> for my working dirs. For one I want to be able to use different branches (like 5.3, 5.4 and master) at the same time and I want to quickly test different PHP configurations, like builds using thread-safety or debug mode on or off.</p> 
<p>A simple approach for this is to use out-of-tree builds, something like that:</p> 
<blockquote> 
<p>$ git clone ....php-src.git<br />$ (cd php-src &amp;&amp; ./buildconf)<br />$ mkdir build-master-minimal<br />$ cd build-master-minimal<br />$ ../php-src/configure --disable-all<br />$ make</p> 
</blockquote> 
<p>This allows having both requirements full-filled as you can have build dirs for each branch and each configuration. Nice, but in the long run quite confusing as you always have to make sure php-src has the correct branch checked out, matching the build dir you're currently building in, else you will create a mess.</p> 
<p>Thankfully there is a nice solution to <a href="https://wiki.php.net/vcs/gitfaq#multiple_working_copies_workflow">have multiple checkouts using git-new-workdir</a>. So one can easily setup the branches and build dirs. Now it's still quite some repetitive work to create a structure using different branches and a set of different build dirs for each branch. Therefore I've created a simple shell script to do this quickly on my different machines and <a href="https://github.com/johannes/create-php-workdir">pushed the script to github</a> in case anybody wants to have a similar structure, and maybe improve the script. But be warned: The script is really an ad hoc thing for me to get started.<br /></p> 
            </div>
        </content>
        <dc:subject>git</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>php git</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/167-Some-videos.html" rel="alternate" title="Some videos" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2012-04-01T22:33:00Z</published>
        <updated>2012-04-01T23:24:23Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=167</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=167</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/167-guid.html</id>
        <title type="html">Some videos</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>Over the years a few videos of my presentations and some interviews were published. I've collected the ones I found and put them on <a href="/yt/?piwik_campaign=blogvideos">a single web page</a>. The oldest is from 2009 the latests just from February this year. Enjoy.</p> 
<p> If you have another video which I missed: Please let me know!<br /></p> 
            </div>
        </content>
        <dc:subject>php</dc:subject>
<dc:subject>php conferences</dc:subject>
<dc:subject>video</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/166-Testing-persistent-connection-and-thread-safety-features-in-PHP.html" rel="alternate" title="Testing persistent connection and thread-safety features in PHP" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2012-03-20T21:23:51Z</published>
        <updated>2012-03-20T21:23:51Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=166</wfw:comment>
    
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=166</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/166-guid.html</id>
        <title type="html">Testing persistent connection and thread-safety features in PHP</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>
By default PHP provides shared-nothing environments to ensure that whatever happens to PHP's state in one request has no effect on other requests, so all function tables are cleaned up, all file handles are closed etc. In a few rare cases this is not what people like, for that PHP introduced &quot;<a href="http://php.net/features.persistent-connections">persistent connections</a>&quot; of different kinds. Testing those is a bit annoying as you have to configure a webserver and ensure to hit the same instance over the course of a test and then use a load generator, probably one which can detect a failure. Additionally by having a webserver in the game there is more code being executed, which might mean an additional source for trouble while debugging. An alternative might be using FastCGI, while that adds it's own issues for such a test.<br /></p> 
<p>To solve this for myself I, some time ago, wrote a PHP SAPI module called <a href="https://github.com/johannes/pconn-sapi">pconn</a> and pushed it to github. (A SAPI is the component in PHP which implements the communication with the web server or whatever triggers PHP requests) The general idea was to have a lightweight SAPI which does nothing but emulate a bunch of requests. I had it some where on my list of things to blog about, but well, low prio.</p> 
<p>Now some time later it seems like Derick was doing some stuff with persistent connections, too, and figured that the new embedded web server is a good thing for such tests, too. While he didn't know about my solution, as one could see in a short discussion on twitter we had:<br /></p> 
<blockquote> 
<p>In other news, the new CLI web server in PHP 5.4 is brilliant for debugging issues with extensions that span more than one request.</p>— Derick Rethans (@derickr) <a data-datetime="2012-03-15T10:50:49+00:00" href="https://twitter.com/derickr/status/180244655743565824">March 15, 2012</a> 
</blockquote> 
<blockquote> 
<p>@<a href="https://twitter.com/derickr">derickr</a> for that you could also use <a href="https://t.co/CehrUb8K" title="https://github.com/johannes/pconn-sapi">github.com/johannes/pconn…</a> which also does multithreading <img src="http://schlueters.de/blog/templates/default/img/emoticons/smile.png" alt=":-)" style="display: inline; vertical-align: bottom;" class="emoticon" /></p>— Johannes Schlüter (@phperror) <a href="https://twitter.com/phperror/status/180299729903697921" data-datetime="2012-03-15T14:29:40+00:00">March 15, 2012</a> 
</blockquote> 
<blockquote> 
<p>@<a href="https://twitter.com/phperror">phperror</a>: You need to write about that stuff :-þ</p>— Derick Rethans (@derickr) <a data-datetime="2012-03-15T14:35:34+00:00" href="https://twitter.com/derickr/status/180301217052901376">March 15, 2012</a> 
</blockquote> 
<p>Now I've contradicted myself: Above I was proudly writing about this being lightweight and easy to debug, but in the tweet I mentioned threading. And well threading always includes lots of trouble to code. But yeah, over time I figured out that this was a good foundation to solve a second issue which has has to be done for PHP: PHP can be run in threaded environments, which in general is not advised. When doing that the old party rule applies: What happens in a thread stays in thread. Different threads should not impact the requests handled in other threads. Now testing for race conditions is even harder than testing persistent connections and additional web server code hurts even more. So my little SAPI became a lot bigger and can now be compiled in two modes. Either simple and short in non threaded mode or with all the extra stuff in threaded-mode which will allow running PHP requests in parallel threads in loops.</p>
<p>In case you find yourself working on some PHP extensions where this might help: Check the github repository and the <a href="https://github.com/johannes/pconn-sapi/blob/master/README">README</a> and drop me a line if anything is unclear.</p> 
            </div>
        </content>
        <dc:subject>pconn</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>php extensions</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/165-Upcoming-talks.html" rel="alternate" title="Upcoming talks" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2012-01-12T10:54:40Z</published>
        <updated>2012-01-12T12:23:59Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=165</wfw:comment>
    
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=165</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/9-MySQL" label="MySQL" term="MySQL" />
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/165-guid.html</id>
        <title type="html">Upcoming talks</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>Over the last few weeks I had been quite silent, but that's about to change: Over the next few weeks I'll give a few presentations. Feel free to join any of those.</p> 
<ul> 
<li>January, 18th: <a href="http://www.mysql.com/news-and-events/web-seminars/display-680.html">Erstellung hochperformanter PHP-Anwendungen mit MySQL</a> (German)<br />MySQL Webinar, Online</li> 
<li>February, 9th: <a href="http://www.oracle.com/webapps/events/ns/EventsDetail.jsp?p_eventId=148478&amp;src=7314534&amp;src=7314534&amp;Act=240">MySQL Konnectoren</a> (German)<br />OTN Developer Day: MySQL, Frankfurt, Germany</li> 
<li>February 24th/25th: <a href="http://www.phpconference.co.uk/talk/php-under-hood">PHP under the hood</a> (English)<br />PHP UK Conference, London, UK</li> 
</ul> 
            </div>
        </content>
        <dc:subject>conferences</dc:subject>
<dc:subject>mysql</dc:subject>
<dc:subject>mysqlde</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>travel</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/164-High-Performance-PHP-Session-Storage-on-Scale.html" rel="alternate" title="High Performance PHP Session Storage on Scale" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2011-11-17T15:34:00Z</published>
        <updated>2011-11-19T17:59:03Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=164</wfw:comment>
    
        <slash:comments>8</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=164</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/9-MySQL" label="MySQL" term="MySQL" />
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/164-guid.html</id>
        <title type="html">High Performance PHP Session Storage on Scale</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>One of the great things about the HTTP protocol, besides <a href="http://tools.ietf.org/html/rfc2324">status code 418</a>, is that it's stateless. A web server therefore is not required to store any information on the user or allocate resources for a user after the individual request is done. By that a single web server can handle many many many different users easily, and well if it can't anymore one can add a new server, put a simple load balancer in front and scale out. Each of those web servers then handles its requests without the need for communication which leads to linear scaling (assuming network provides enough bandwidth etc.).</p> 
<p>Now the Web isn't used for serving static documents only anymore but we have all these fancy web apps. And those applications often have the need for a state. The most trivial information they need is the current user. HTTP is a great protocol and provides a way to do authentication which works well with its stateless nature - unfortunately this authentication is implemented badly in current clients. Ugly popups, no logout button, ... I don't have to tell more I think. For having nicer login systems people want web forms. Now the stateless nature of HTTP is a problem: The user may login and then browse around. On later requests it should still be known who that user is - with a custom HTML form based login alone this is not possible. A solution might be cookies. At least one might think so for a second. But setting a cookie &quot;this is an authorized user&quot; alone doesn't make sense as it could easily be faked. Better is to simply store a random identifier in a cookie and then keep a state information on the server. Then all session data is protected and only the user who knows this random identifier is authenticated. If this identifier is wisely chosen and hard to guess this works quite well. Luckily this is a mostly PHP- and MySQL-focused blog and as PHP is a system for building web applications this functionality is part of the core language: The <a href="http://php.net/session">PHP session module</a>.</p> 
<p>The session module, which was introduced in PHP 4, partly based on work on the famous phplib library, is quite a fascinating piece of code. It is open and extendable in so many directions but still so simple to use that everybody uses it, often newcomers learn about it on their first day in PHP land. Of course you can not only store the information whether the user is logged in but cache some user-specific data or keep the state on some transactions by the user, like multi-page forms or such.<br /></p> 
<p>In its default configuration session state will be stored on the web server's file system. Each session's data in its own file in serialized form. If the filesystem does some caching or one uses a ramdisk or something this can be quite efficient. But as we suddenly have a state on the web server we can't scale as easily as before anymore: If we add a new server and then route a user with an existing session to the new server all the session data won't be there. That is bad. This is often solved by a configuration of the load balancer to route all requests from the same user to the same web server. In some cases this works quite ok, but it is often seen that this might cause problems. Let's assume you want to take a machine down for maintenance. All sessions there will die. Or imagine there's a bunch of users who do complex and expensive tasks - then one of your servers will have a hard time, giving these users bad response times which feels like bad service, even though your other systems are mostly idle.</p> 
<p>A nice solution for this would be to store the sessions in a central repository which can be accessed from all web servers.</p> <br /><a href="http://schlueters.de/blog/archives/164-High-Performance-PHP-Session-Storage-on-Scale.html#extended">Continue reading "High Performance PHP Session Storage on Scale"</a>
            </div>
        </content>
        <dc:subject>memcache</dc:subject>
<dc:subject>memcached</dc:subject>
<dc:subject>mysql</dc:subject>
<dc:subject>mysql cluster</dc:subject>
<dc:subject>performance</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>php session</dc:subject>
<dc:subject>scalability</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/163-mysqli_result-iterations.html" rel="alternate" title="mysqli_result iterations" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2011-11-14T15:19:18Z</published>
        <updated>2011-11-17T11:19:58Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=163</wfw:comment>
    
        <slash:comments>2</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=163</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/9-MySQL" label="MySQL" term="MySQL" />
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/163-guid.html</id>
        <title type="html">mysqli_result iterations</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>For the last few months I had quite a few MySQL blog posts and didn't have anything from my &quot;<a href="http://schlueters.de/blog/plugin/tag/php%FFnext">new features in PHP [trunk|5.4]</a>&quot; series. This article is a bridge between those two. The <a href="http://svn.php.net/viewvc/php/php-src/branches/PHP_5_4/NEWS?revision=HEAD&amp;view=markup">PHP 5.4 NEWS</a> file has a small entry:</p> 
<p> </p> 
<blockquote>MySQLi: Added iterator support in MySQLi. mysqli_result implements Traversable. (Andrey, Johannes)<br /></blockquote> 
<p>From the outside it is a really small change and easy to miss. The mentioned class, mysqli_result, implements an interface which adds no new methods. What once can't see is that this relates to some internal C-level functions which can be called by the engine for doing a foreach iteration on objects of this class. So with PHP 5.4 you don't have to use an &quot;ugly&quot; while construct anymore to fetch rows from a mysqli result but can simply do a foreach:</p> 
<blockquote> 
<pre><a title="" target="" href="http://php.net/mysqli_report">mysqli_report</a>(MYSQLI_REPORT_STRICT);
try {
    $mysqli = new mysqli(/* ... */);
    foreach ($myslqi-&gt;<a title="" target="" href="http://php.net/mysqli.query">query</a>("SELECT a, b, c FROM t") as $row) {
        /* Process $row which is an associative array */
    }
} catch (mysqli_sql_exception $e) {
    /* an error happened ... */
}
</pre> 
</blockquote> 
<p>I'm configuring mysqli in a way to throw exceptions on error. This is useful in this case as mysqli::query() might return false in the case of an error. Passing false to a foreach will give a fatal error, so I'd need a temporary variable and a check in front of the foreach loop, with exceptions I simply do the error handling in the catch block.</p> 
<p>One thing to note is that mysqli is using buffered results (&quot;store result&quot;) by default. If you want to use unbuffered result sets (&quot;use result&quot;) you can easily do that by setting the flag accordingly:</p> 
<blockquote> 
<pre>foreach ($myslqi-&gt;query("SELECT a, b, c FROM t", MYSQLI_USE_RESULT) as $row) {
    /* ... */
}
</pre> 
</blockquote> 
<p>People who are advanced with iterators in PHP might ask &quot;Why did you implement Traversable only, not <a href="http://php.net/iterator">Iterator</a>?&quot; - the main reason is that we simply didn't want to. The mysqli_result class already has quite a few methods and we didn't want to make the interface confusing. If you need an Iterator class for some purpose you can simply wrap mysqli_result in an <a href="http://php.net/IteratorIterator">IteratoIterator</a>.<br /></p> 
            </div>
        </content>
        <dc:subject>mysql</dc:subject>
<dc:subject>mysqli</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>php 5.4</dc:subject>
<dc:subject>php oo</dc:subject>
<dc:subject>php.iterator</dc:subject>
<dc:subject>php.next</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/162-mysqlnd_qc-and-Symfony2.html" rel="alternate" title="mysqlnd_qc and Symfony2" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2011-10-07T20:52:00Z</published>
        <updated>2011-10-14T07:23:53Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=162</wfw:comment>
    
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=162</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/9-MySQL" label="MySQL" term="MySQL" />
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/162-guid.html</id>
        <title type="html">mysqlnd_qc and Symfony2</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>Previously I was writing about combining <a href="http://schlueters.de/blog/archives/161-Symfony-2-and-mysqlnd.html">Symfony2 and mysqlnd</a> to get more statistics on what is going on below the surface in the database communication when using a Symfony2 application via the Symfony2 profiler. Now that's not all that can be done and I gave some ideas for extending this. One idea was adding mysqlnd_qc support. mysqlnd_qc is the client side query cache plugin for mysqlnd. This provides a client-side cache for query results transparently without changing the application.</p> 
<p> 
<iframe width="670" height="550" src="/presentations/#p=20101030_barcelona_MySQL_Caching">&amp;amp;amp;lt;span id=&amp;amp;amp;quot;XinhaEditingPostion&amp;amp;amp;quot;&amp;amp;amp;gt;&amp;amp;amp;lt;/span&amp;amp;amp;gt;&amp;amp;amp;amp;amp;lt;span id=&amp;amp;amp;amp;amp;quot;XinhaEditingPostion&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;gt;&amp;amp;amp;amp;amp;lt;/span&amp;amp;amp;amp;amp;gt;</iframe> 
</p> 
<p><a href="http://schlueters.de/blog/uploads/screenshots/symfony2_mysqlnd_qc.png" class="serendipity_image_link"><!-- s9ymdb:70 --><img style="width: 162px; height: 62px;" src="http://schlueters.de/blog/uploads/screenshots/symfony2_mysqlnd_qc.serendipityThumb.png" class="serendipity_image_right" /></a>A nice thing about this plugin, for this context here, is the function <a href="http://php.net/mysqlnd_qc_get_query_trace_log">mysqlnd_qc_get_query_trace_log()</a> which provides information about each query being executed. Not only the query string but also some timing (execution time, result storage time) and a stack trace so you can see where in the code a query was executed. I've added this functionality to the <a href="https://github.com/johannes/JSMysqlndBundle">JSMysqlndBundle</a> as you can see in the <a href="http://schlueters.de/blog/uploads/screenshots/symfony2_mysqlnd_qc.png" class="serendipity_image_link">screenshot</a>. I won't show a screenshot about what happens if you click the stacktrace link as this currently breaks the layout a bit, but maybe somebody wants to make this nicer? - Or maybe even feels motivated to make it even better using <a href="http://docs.php.net/manual/en/book.mysqlnd-uh.php">mysqlnd_uh</a> (which, as of today, has docs, thanks to Ulf) Feel free to contact me to talk about ideas! <img src="http://schlueters.de/blog/templates/default/img/emoticons/smile.png" alt=":-)" style="display: inline; vertical-align: bottom;" class="emoticon" /><br /></p> 
            </div>
        </content>
        <dc:subject>coding</dc:subject>
<dc:subject>mysqlnd</dc:subject>
<dc:subject>mysqlnd_qc</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>symfony2</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/161-Symfony-2-and-mysqlnd.html" rel="alternate" title="Symfony 2 and mysqlnd" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2011-10-02T12:23:00Z</published>
        <updated>2011-10-07T20:58:53Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=161</wfw:comment>
    
        <slash:comments>6</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=161</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/9-MySQL" label="MySQL" term="MySQL" />
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/161-guid.html</id>
        <title type="html">Symfony 2 and mysqlnd</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>In a <a href="http://schlueters.de/blog/archives/159-mysqlnd-plugins-and-json.html">previous blog posting</a> I was mentioning that I'm working on a small hobby PHP project. As I'm using this project to update myself to current frameworks I've decided to use Symfony2. Symfony provides a nice feature, which is the Symfony Profilier, an extensive logging and reporting system for Symfony2 developers to understand what's going on. A part of it is the Doctrine query logger which lists all database queries executed by Doctrine and their execution time.</p> 
<p><a href="http://schlueters.de/blog/uploads/screenshots/symfony_mysqlnd.png" class="serendipity_image_link"><!-- s9ymdb:69 --><img width="110" height="109" src="http://schlueters.de/blog/uploads/screenshots/symfony_mysqlnd.serendipityThumb.png" class="serendipity_image_left" /></a>This is nice but when we're using mysqlnd in our PHP build we have more information available. &quot;So why not use that information,&quot; I thought and built a new bundle for Symfony2 doing exactly that. The <a href="http://github.com/johannes/JSMysqlndBundle">JSMysqlndBundle</a> will take all the <a href="http://php.net/mysqlnd.stats">150 or so statistic values</a> collected, so they can be seen in the profiler (click screenshot for a larger view).</p> 
<p>As this is the initial value, a quick Sunday morning hack, it has not all features I can imagine. Things one could do include</p> 
<ul> 
<li>Provide information on caching decisions and behavior when <a href="http://php.net/mysqlnd_qc">mysqlnd_qc</a> is used</li> 
<li>Provide replication-related decisions when the new <a href="http://php.net/mysqlnd_ms">mysqlnd replication and load balancing plugin</a> is used</li> 
<li>Take David's <a href="http://blog.mayflower.de/archives/578-MySQLnd-Plugins-Writing-a-MySQL-Query-Logger-in-PHP.html">mysqlnd_uh-based query logging</a> ideas and provide more information on any executed query</li> 
<li>....</li> 
</ul>Any takers? - Code away!<br /> 
            </div>
        </content>
        <dc:subject>coding</dc:subject>
<dc:subject>mysqlnd</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>symfony2</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/150-MySQL-Query-Analyzer-and-PHP.html" rel="alternate" title="MySQL Query Analyzer and PHP" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2011-09-29T22:26:00Z</published>
        <updated>2011-09-29T23:35:57Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=150</wfw:comment>
    
        <slash:comments>2</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=150</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/9-MySQL" label="MySQL" term="MySQL" />
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/150-guid.html</id>
        <title type="html">MySQL Query Analyzer and PHP</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>Today we've released a few things for PHP and MySQL users: One is the first (and probably only) beta of the <a href="http://pecl.php.net/mysqlnd_ms">mysqlnd_ms plugin</a> for MySQL Replication and Load Balancing support and the first GA version of a PHP plugin for the Query Analyzer of the MySQL Enterprise Monitor.</p> 
<p>Ulf <a href="http://blog.ulf-wendel.de/">blogged a lot</a> about mysqlnd_ms, so I don't have to repeat him here. what I want to talk about is the other one. So what is that about?<br /></p> 
<p>When running a PHP-based application with MySQL it is often quite interesting to see what actually happens on the database sever. Besides monitoring of the system load etc. it is often interesting to see what queries are actually executed and which of them are expensive. A part of MySQL Enterprise Monitor is the <a href="http://mysql.com/products/enterprise/query.html">MySQL Query Analyzer</a> which helps answering these questions.</p> 
<p>Traditionally the MySQL Query Analyzer&#160; was based on MySQL Proxy which is configured to sit between the application and the MySQL server and collects all relevant data.<br /></p> 
<p>Now in the new <a href="http://blogs.oracle.com/mysqlenterprise/entry/mysql_enterprise_monitor_2_33">2.3.7 release</a> of the MySQL Enterprise Monitor we have enhanced this for PHP users: We now provide a plugin which can be loaded in PHP and which will provide data for the Query Analyzer directly from within PHP.</p> 
<p> <!-- s9ymdb:67 --><img width="1053" height="690" src="http://schlueters.de/blog/uploads/screenshots/mem_quan_php1.png" class="serendipity_image_center" style="max-width:100%" /></p> 
<p>By that we don't only reduce the latency for the data collection but we can provide more information about the current environment.</p> 
<p><!-- s9ymdb:68 --><img width="837" height="694" src="http://schlueters.de/blog/uploads/screenshots/mem_quan_php2.png" class="serendipity_image_center" /> </p> 
<p>In the query detail window you now don't only see general query statistics but also a stack trace from the application, so you can immediately identify the part of the application which should be improved. So above you can see a few screenshots I made from this server showing some insights of this blog where I was testing the plugin.</p> 
<p>If you want to learn more checkout the <a href="http://dev.mysql.com/doc/mysql-monitor/2.3/en/mem-qanal-using-cphp.html">documentation</a> and <a href="http://mysql.com/products/enterprise/monitor.html">product pages</a>. Hope you like it!<br /></p> 
            </div>
        </content>
        <dc:subject>cta</dc:subject>
<dc:subject>mysql</dc:subject>
<dc:subject>mysqlnd</dc:subject>
<dc:subject>mysqlnd plugins</dc:subject>
<dc:subject>query analyzer</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/160-Direct-MySQL-Stream-Access-Revised.html" rel="alternate" title="Direct MySQL Stream Access - Revised" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2011-09-26T10:56:00Z</published>
        <updated>2011-09-26T11:53:17Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=160</wfw:comment>
    
        <slash:comments>3</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=160</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/9-MySQL" label="MySQL" term="MySQL" />
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/160-guid.html</id>
        <title type="html">Direct MySQL Stream Access - Revised</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>Roughly three years ago I was writing about <a href="http://schlueters.de/blog/archives/86-Direct-MySQL-Stream-Access.html">Direct MySQL Stream Access</a> - a way to access the low-level stream PHP's mysqlnd library is using. Back then this had been a patch against PHP's mysqli extension. As such a feature is quite dangerous (you can easily mess with the connection state which confuses mysqlnd and/or the MySQL server) we didn't push it into the main PHP tree. Now three years later it's time to look at this again as we don't need to patch PHP anymore.</p> 
<p>Since the mentioned patch was written mysqlnd got a plugin interface about which <a href="http://schlueters.de/blog/plugin/tag/mysqlnd+plugins">I was talking before</a>. This plugin-interface, especially in the version of PHP 5.4, makes it trivial to implement this feature.</p> 
<blockquote> 
<pre>PHP_FUNCTION(mysqlnd_to_stream)
{
&#160;&#160;&#160; zval *conn_zv;
&#160;&#160;&#160; MYSQLND *conn;

&#160;&#160;&#160; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &amp;conn_zv) == FAILURE) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160; return;
&#160;&#160;&#160; }

&#160;&#160;&#160; if (!(conn = zval_to_mysqlnd(conn_zv))) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160; php_error_docref(NULL TSRMLS_CC, E_WARNING,
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "Passed variable is no mysqlnd based connection");
&#160;&#160;&#160;&#160;&#160;&#160;&#160; RETURN_FALSE;
&#160;&#160;&#160; }

&#160;&#160;&#160; php_stream_to_zval(conn-&gt;net-&gt;stream, return_value);
}
&#160;</pre> 
</blockquote> 
<p>If you take a function like the one shown above and add some general PHP infrastructure you are done. The key function here is the function <em>MYSQLND* zval_to_mysqlnd(zval *connection)</em> which takes a PHP variable as parameter and in case it is a MySQL connection (ext/mysql, mysqli or pdo_mysql) will return the corresponding MYSQLND pointer which gives access to the stream which then has to be packed into a PHP variable, again. The nice thing, compared to the old version is not only that it is a plugin which can be loaded into PHP as shared extension via php.ini but also that it works with all MySQL extensions, not only mysqli as the one before.</p> 
<p>You can <a href="http://schlueters.de/blog/uploads/code/mysqlnd_to_stream.tar.bz2">download the complete source</a>, but be warned: This is experimental stuff and not supported in any way, but I hope good enough to get a feeling what's possible with mysqlnd.<br /></p> 
            </div>
        </content>
        <dc:subject>coding</dc:subject>
<dc:subject>mysqlnd</dc:subject>
<dc:subject>mysqlnd plugins</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>php extensions</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/159-mysqlnd-plugins-and-json.html" rel="alternate" title="mysqlnd plugins and json" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2011-09-14T11:27:00Z</published>
        <updated>2011-09-16T07:56:15Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=159</wfw:comment>
    
        <slash:comments>3</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=159</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/9-MySQL" label="MySQL" term="MySQL" />
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/159-guid.html</id>
        <title type="html">mysqlnd plugins and json</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>Some time ago I was already writing about the <a href="http://schlueters.de/blog/archives/146-mysqlnd-plugins-for-PHP-in-practice.html">power included with mysqlnd plugins</a> and how they can they can be used transparently to help you with your requirements without changing your code. But well, as mysqlnd plugins in fact are regular PHP extensions they can export functions to the PHP userland and providing complete new functionality.</p> 
<p>In my spare time I'm currently writing a shiny Web 2.0 application where I'm heavily using AJAX-like things, so what I do quite often in this application is, basically this: Check some pre-conditions (permissions etc.) then select some data from the database, do a fetch_all to get the complete result set as an array and run it through json_encode; or to have it in code:</p> 
<blockquote> 
<pre>&lt;?php
$m = new MySQLi(/*...*/);
check_whether_the_user_is_checked_in_and_allowed_to_see_this();
$result = $m-&gt;query("SELECT a,b,c,d FROM t WHERE e=23");
echo json_encode($result-&gt;fetch_all());
?&gt;
</pre> 
</blockquote> 
<p>Of course that example is simplified as I'm using the Symfony 2 framework for this project. When writing a similar function for the 5th time I wondered whether I really need to create the temporary array and all these temporary elements in it.</p> 
<p>So I wrote a mysqlnd plugin.</p> 
<p>The mysqlnd_query_to_json plugin (hey what a name!) provides a single function, mysqlnd_query_to_json(), which takes two parameters, a connection identifier and an SQL query, and returns a JSON string containing the result set. The connection identifier can be a mysql resource, a mysqli object or even a PDO object. The resulting JSON string will be created directly from the network buffer without the need of temporary complex structures. Using the above example would create code like this:</p> 
<blockquote> 
<pre>&lt;?php
$m = new MySQLi(/*...*/);
check_whether_the_user_is_checked_in_and_allowed_to_see_this();
echo mysqlnd_query_to_json($m, "SELECT a,b,c,d FROM t WHERE e=23");
?&gt;
</pre> 
</blockquote> 
<p>The plugin, which you can <a href="http://schlueters.de/blog/uploads/code/mysqlnd_query_to_json.tar.bz2">find here</a>, requires PHP 5.4 and has a few limitations as it knows nothing about MySQL bitfields or escaping of unicode characters for creating fully valid JSON data and Andrey called it, for good reasons, a hack. Neither did I benchmark it, yet as I merely share it to show what's possible and maybe start some discussion on what is actually needed.</p> 
<p>If you want to learn more on these topics I also suggest to check the <a href="http://www.mysql.com/news-and-events/web-seminars/">MySQL Webinar page</a> frequently as Ulf is going to hold a Webinar on myslqnd plugins in October!<br /></p> 
            </div>
        </content>
        <dc:subject>coding</dc:subject>
<dc:subject>mysql</dc:subject>
<dc:subject>mysqlnd</dc:subject>
<dc:subject>mysqlnd plugins</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>php extensions</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/156-Improvements-for-PHP-application-portability-in-PHP.next.html" rel="alternate" title="Improvements for PHP application portability in PHP.next" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2011-07-25T20:44:00Z</published>
        <updated>2011-07-30T17:29:29Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=156</wfw:comment>
    
        <slash:comments>7</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=156</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/156-guid.html</id>
        <title type="html">Improvements for PHP application portability in PHP.next</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>I was writing about <a href="http://schlueters.de/blog/plugin/tag/php%FFnext">PHP.next before</a>, many things improved there meanwhile. Most notably we have a committed version number: The next PHP release will be called PHP 5.4. The topic I want to talk about today is &quot;Improved application portability&quot; which covers multiple small changes which aim at making it simpler for developers to write applications working on any PHP setup.</p> 
<p><strong>Separating <em>&lt;?=</em> from <em>short_open_tags</em></strong></p> 
<p>PHP knows quite a few ways to separate PHP code from surrounding text (usually HTML), most applications use <em>&lt;?php</em> as that works on every system. There is a short form of this, <em>&lt;?</em>, which can be disabled using php.ini's short_open_tags setting. Being able to disable this is important when embedding PHP code into XML documents containing XML processing instructions. Now we also have <em>&lt;?=</em> which, basically, is a shortcut for <em>&lt;?php echo</em>. This tag is useful when using PHP as templating language as it prevents cluttered code. The issue in current version of PHP is that this is bound to short_open_tags, so portable applications can't rely on it. But PHP 5.4 will bring the solution: <em>&lt;?=</em> will always be there, independently from short_open_tags. Yay!</p> 
<p><strong>No more magic_quotes</strong></p> 
<p>In the old times it was easy to write code using PHP.</p> 
<blockquote> 
<p>&lt;?php<br />$q = mysql_query(&quot;SELECT * FROM t WHERE name = '$name' &quot;);<br />?&gt;</p> 
</blockquote> 
<p>And you had, thanks to register_globals, some data to work on and this was mostly secure as PHP automatically escaped request data. But well this escaping worked only in a few cases acceptable good. Besides not knowing anything about other encodings or DBMS-specific escape sequences it also failed for non-string values as in</p> 
<blockquote> 
<p>&lt;?php<br />
$q = mysql_query(&quot;SELECT * FROM t WHERE id = $id &quot;);<br />
?&gt;</p> 
</blockquote> 
<p>Where the external value wasn't escaped. So portable applications, which aim at being secure nowadays have to check whether magic_quote_gpc is enabled, then remove the &quot;bad&quot; quotes and then finally escape again using the appropriate way. That's quite&#160; an annoyance and doing this the wrong way can cause bad bugs (like forcing such a replacement logic in an endless recursion by providing arrays) So nobody really likes magic_quotes. So with PHP 5.4 they are gone. No more need to worry about them. Use the proper escaping and you're done. Wonderful. Only issue: Legacy applications might rely on magic_quotes so when upgrading PHP make sure the application does the required escaping itself so almost-secure applications won't become insecure.</p> 
<p><strong>Dropped explicit --enable-zend-multibyte compile-time option</strong></p> 
<p>Especially in Asia people use multi-byte encodings which aren't ASCII-compatible so mixing them with PHP code might be hard. In current versions of PHP there is a compile-time option to enable a special multibyte mode for the engine which will handle this in the engine so PHP code can be provided using these encodings. By this portable applications had a hard time due to this conversion (not) being done. Thanks to the work by Dmitry and Moriyoshi this mode is now always enabled whithout penalty for people not depending on it and the extended functionality from mbstring can be provided as a shared module. By this distributors can provide a single build which will work for everybody.</p> 
<p><strong>Closing remarks</strong> <br /></p> 
<p>As always in this series: Be aware that things discussed here might change. Please try out the current snapshot of PHP 5.4 and test it with your applications. No we can still fix backwards compatibility breaks. fixing them after a release will possibly break it for people depending on the new behavior. Happy coding!<br /></p> 
            </div>
        </content>
        <dc:subject>coding</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>php 5.4</dc:subject>
<dc:subject>php.next</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/158-PHP-5.4-Alpha-1.html" rel="alternate" title="PHP 5.4 Alpha 1" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2011-07-02T00:23:00Z</published>
        <updated>2011-07-04T07:07:26Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=158</wfw:comment>
    
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=158</wfw:commentRss>
    
    
        <id>http://schlueters.de/blog/archives/158-guid.html</id>
        <title type="html">PHP 5.4 Alpha 1</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>Recently <a href="http://qa.php.net">PHP 5.4.0 Alpha 1</a> was released and the PHP development team is asking every PHP user to test it. In this blog I have some articles about upcoming features in that version. Now is a good time to test 5.4 in combination with your applications spot mistakes (complain now if we break compatibility, now we could fix it ...) and a good time to prepare your knowledge.</p> 
<p>These are the articles I published here:</p> 
<ul> 
<li><a href="http://schlueters.de/blog/archives/129-Mind-the-encodings!.html">Mind the encoding</a></li> 
<li><a href="http://schlueters.de/blog/archives/133-Now-in-trunk-Improved-interactive-shell.html">Improved interactive shell</a></li> 
<li><a href="http://schlueters.de/blog/archives/135-Jason,-let-me-help-you!.html">Jason, let me help you</a></li> 
<li><a href="http://schlueters.de/blog/archives/138-Features-in-PHP-trunk-Array-dereferencing.html">Array dereferencing</a></li> 
<li><a href="http://schlueters.de/blog/archives/147-Changes-in-PHP-trunk-No-more-extension-for-sqlite-version-2.html">No more extension for SQLite 2</a></li> 
<li><a href="http://schlueters.de/blog/archives/151-Upload-Progress-in-PHP-trunk.html">Upload progress</a></li> 
</ul> 
<p>I also have articles on a feature which does not make that release:</p> 
<ul> 
<li><a href="http://schlueters.de/blog/archives/139-Scalar-type-hints-in-PHP-trunk.html">Scalar type hints in PHP trunk</a></li> 
<li><a href="http://schlueters.de/blog/archives/148-More-on-scalar-type-hints-in-PHP-trunk.html">More on scalar type hints in PHP</a></li> 
</ul>I plan to continue that series, focusing on things which might be overseen easily. It's a bit time till 5.4 will be released as GA but the more you test it and give feedback the better it will be! <img src="http://schlueters.de/blog/templates/default/img/emoticons/smile.png" alt=":-)" style="display: inline; vertical-align: bottom;" class="emoticon" /><br /> 
            </div>
        </content>
        <dc:subject>coding</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>php 5.4</dc:subject>
<dc:subject>php qa</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/157-OSCON-2011.html" rel="alternate" title="OSCON 2011" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2011-06-30T22:41:00Z</published>
        <updated>2011-07-04T07:15:51Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=157</wfw:comment>
    
        <slash:comments>4</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=157</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/157-guid.html</id>
        <title type="html">OSCON 2011</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>This year I'll attend OSCON for the first time. I'll give two talks:</p> 
<ul> 
<li><a href="http://www.oscon.com/oscon2011/public/schedule/detail/18799">PHP and MySQL - Recent Developments</a><br />PHP’s MySQL support recently received many changes under the hood. PHP 5.3 introduced mysqlnd – the MySQL native driver which is a replacement for libmysql deeply bound into PHP. In this presentation you will learn what the PHP and MySQL development teams were up to. After starting with an introduction of the PHP-stack, demystifying things like mysqli, mysqlnd or PDO, this presentation will show you how to build mysqlnd plugins as PHP C extension and hooking into mysqlnd from PHP  userland. It will also discuss existing plugins like a client side query cache or a module for doing read-write-splitting, both working transparently, without changes to your application.</li> 
<li><a href="http://www.oscon.com/oscon2011/public/schedule/detail/18904">PHP Under the hood</a><br />
The beauty of PHP is that everybody can read the code and see the inner workings of software. But understanding concepts from reading code isn’t often helpful. Especially if you are no pro in that language. This presentation will take apart many parts of the PHP runtime, describe the concepts behind so attendees understand the inner workings without actually reading C code. Concepts covered include HashTables, the foundation for PHP  arrays and many other internal data structures, the reference counting mechanism, which is important for writing efficient code as well as the overall executor.</li> 
</ul> 
<p>In case you can't make it to these talks but want to talk to me you'll probably find me at the Oracle booth where I'll also try to give some short talks on some topics to be defined (any wishes?)</p> 
<p>&#160;In case you're not interested in me and my talks but MySQL there are a few sessions by other MySQL Engineers:</p> 
<ul> 
<li><a href="http://www.oscon.com/oscon2011/public/schedule/detail/19057">MySQL Replication Update</a></li> 
<li><a href="http://www.oscon.com/oscon2011/public/schedule/detail/19223">InnoDB: Performance and Scalability Features</a></li> 
<li><a href="http://www.oscon.com/oscon2011/public/schedule/detail/18788">Python Utilities for Managing MySQL Databases</a></li> 
<li><a href="http://www.oscon.com/oscon2011/public/schedule/detail/18785">The MySQL Time Machine</a></li> 
</ul>In case you want to attend you can use the code <em>os11fos</em> which should give you a 20% discount. <br /> 
            </div>
        </content>
        <dc:subject>conferences</dc:subject>
<dc:subject>mysql</dc:subject>
<dc:subject>oscon</dc:subject>
<dc:subject>php</dc:subject>
<dc:subject>travel</dc:subject>

    </entry>
    <entry>
        <link href="http://schlueters.de/blog/archives/155-Escaping-from-the-statement-mess.html" rel="alternate" title="Escaping from the statement mess" />
        <author>
            <name>Johannes Schlüter</name>
                    </author>
    
        <published>2011-05-18T13:00:00Z</published>
        <updated>2011-05-22T16:59:55Z</updated>
        <wfw:comment>http://schlueters.de/blog/wfwcomment.php?cid=155</wfw:comment>
    
        <slash:comments>22</slash:comments>
        <wfw:commentRss>http://schlueters.de/blog/rss.php?version=atom1.0&amp;type=comments&amp;cid=155</wfw:commentRss>
    
            <category scheme="http://schlueters.de/blog/categories/3-PHP" label="PHP" term="PHP" />
    
        <id>http://schlueters.de/blog/archives/155-guid.html</id>
        <title type="html">Escaping from the statement mess</title>
        <content type="xhtml" xml:base="http://schlueters.de/blog/">
            <div xmlns="http://www.w3.org/1999/xhtml">
                <p>One of the issues Web Developers face is making their application robust to prevent SQL injection attacks. Different approaches exist which help. Sometimes people use large abstraction layers (which, sometimes, don't make anything safe ...) and sometimes people use prepared statements as a way to secure queries. Now prepared statements were a nice invention some 30 years ago abut they weren't meant for making things secure and so they do have some shortcomings: One issue is that preparing and executing a query adds a round-trip to the server where it then requires resources. In a <em>classic</em> application this is no issue. The users starts the application up early in the morning and processes data multiple times so the prepared statement handle is re-used quite some time. The system benefits from early optimisations.&#160; In a typical PHP Web application this isn't the case. A request and therefore a database connection with its associated statement handles lives way less than a second before being thrown away. The PDO MySQL driver, by default, tries to improve that by emulating the prepared statement on the client side. This emulation faces issues as it is lacking the knowledge of what's valid SQL which can lead to strange behaviour (The simple example is $pdo-&gt;prepare(&quot;SELECT * FROM t LIMIT ?&quot;)-&gt;execute(array($_GET['count'])); which will emit an SQL syntax error) and inherits limitations from prepared statements. A second issue with prepared statements is that queries are being built dynamically. A common case which is hard to do with prepared statements is the IN() clause with a dynamic amount of values. With prepared statements you first have to build the list of place holders (the exact amount of place holders (<em>?</em>) separated by a comma, without trailing comma)&#160; and then bind the values and mind the offsets when having other values - this typically becomes ugly code.</p> 
<p>So why not take a step back. - Let's not try to emulate prepared statements but try to make it simpler to construct queries while escaping data?</p> 
<p>An API for doing this might follow the sprintf() semantics and look like this;</p> 
<blockquote> 
<pre>$sql = mysqli_format_query($mysqli, "SELECT * FROM t WHERE f1 = %s AND f2 = %i", "foobar", 23);
</pre> 
</blockquote> 
<p>which would return a string</p> 
<blockquote> 
<pre>SELECT * FROM t WHERE fi = 'foobar' AND f2 = 23
</pre> 
</blockquote> 
<p>which can safely be send to the database. As said the IN clause should work. as we're in PHP we might simply extend it to do this:</p> 
<blockquote> 
<pre>$sql = mysqli_format_query($mysqli, "SELECT * FROM t WHERE f1 IN (%s)", array("foobar", 23));

SELECT * FROM t WHERE f1 IN ('foobar', '23')
</pre> 
</blockquote> 
<p>Well doesn't look fancy? - But there's more: By not pretending to emulate prepared statements we can easily work with more dynamic queries. Something along the lines of</p> 
<blockquote> 
<pre>$sql = mysqli_format_query($mysqli, "SELECT * FROM t WHERE uid = %i", $_SESSION['uid']);
if (isset($option['option1']) {
    $sql .= mysqli_format_query($mysqli, "AND option1 = %s", $option['option1']);
}
if (isset($option['option2']) {
    $sql .= mysqli_format_query($mysqli, "OR option2 = %s", $option['option2']);
}
</pre> 
</blockquote> 
<p>Doing such a thing using prepared statements&#160; or in some <em>classic</em> way becomes way harder to maintain. For playing with this approach I quickly cooked up a simple implementation of that logic which should work well with PHP 5.3 and mysqli:<br /></p> <br /><a href="http://schlueters.de/blog/archives/155-Escaping-from-the-statement-mess.html#extended">Continue reading "Escaping from the statement mess"</a>
            </div>
        </content>
        <dc:subject>coding</dc:subject>
<dc:subject>mysql</dc:subject>
<dc:subject>php</dc:subject>

    </entry>

</feed>
