<?xml version="1.0" encoding="utf-8" ?>

<rss version="0.91" >
<channel>
<title>php-Blogger</title>
<link>http://phpblogger.de/</link>
<description>php-Blogger</description>
<language>de</language>
<image>
        <url>http://phpblogger.de/templates/php-blogger/img/s9y_banner_small.png</url>
        <title>RSS: php-Blogger - php-Blogger</title>
        <link>http://phpblogger.de/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>nginx tips: adding arbitrary output to a response</title>
    <link>http://phpblogger.de/archives/300-nginx-tips-adding-arbitrary-output-to-a-response.html</link>

    <description>
        &lt;span class=&quot;preview&quot;&gt;&lt;a target=&quot;_blank&quot; href=&quot;http://dl.dropbox.com/u/5014780/phpblogger/cd_big.png&quot;&gt;&lt;img src=&quot;http://dl.dropbox.com/u/5014780/phpblogger/cd_big_small.jpg&quot; /&gt;&lt;/a&gt;&lt;/span&gt;

&lt;p&gt;A while ago i wrote about how to use &lt;a target=&quot;_blank&quot; href=&quot;http://wiki.nginx.org/&quot;&gt;nginx&lt;/a&gt; as a proxy to do &lt;a target=&quot;_blank&quot; href=&quot;http://phpblogger.de/archives/283-cookie-based-redirect-mit-nginx.html&quot;&gt;cookie based redirects&lt;/a&gt;. We use this functionality at work to provide easy  access and view the progress of development of each developer.&lt;/p&gt;

&lt;p&gt;I thought it would be nice to have the information, of which developers machine you currently have access to, right on the website. But i always disliked to put functionality to accomplish this inside the framework or even the app itself or have to install / modify some special configuration on each developers machine. I always wanted my proxy to do this kind of work. ... And nginx can.&lt;/p&gt;

&lt;p&gt;It&#039;s the &lt;a target=&quot;_blank&quot; href=&quot;http://wiki.nginx.org/NginxHttpSubModule&quot;&gt;substitution module&lt;/a&gt; of nginx, that can replace arbitrary text in a http response. Nginx must be compiled with the option &lt;tt&gt;--with-http_sub_module&lt;/tt&gt; configured.&lt;/p&gt;

&lt;p&gt;The following rows show how to fill a variable &lt;tt&gt;$name&lt;/tt&gt; with the name of the developer we are accessing the machine of. The statement &lt;tt&gt;sub_filter&lt;/tt&gt; defines the search pattern as first parameter and the replace string as second parameter -- very easy, isn&#039;t it?&lt;/p&gt;

&lt;code&gt;
&lt;pre&gt;
set $name &amp;quot;&amp;quot;
if ($http_cookie ~* &amp;quot;(; )?devredirect=([^;]+)&amp;quot;) {
    set $name $2;
}
sub_filter      &amp;quot;&amp;lt;/body&amp;gt;&amp;quot;       &amp;quot;&amp;lt;div style=&#039;position: fixed; 
    left: 0; top: 0; font-weight: bold; padding: 5px; color: #000; 
    background-color: rgb(235,58,0);&#039;&amp;gt;devredirect: ${name}&amp;lt;/div&amp;gt;
    &amp;lt;/body&amp;gt;&amp;quot;;
&lt;/pre&gt;
&lt;/code&gt;

&lt;p&gt;The following rows show the part of the proxy configuration with the inserted substitution filter:&lt;/p&gt;

&lt;code&gt;
&lt;pre&gt;
server {
    listen          80;
    server_name     .clipdealer.devcenter.int;

    proxy_redirect          off;
    proxy_set_header        Host            $host;
    proxy_set_header        X-Real-IP       $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

    location / {
        set $name &amp;quot;&amp;quot;
        if ($http_cookie ~* &amp;quot;(; )?devredirect=([^;]+)&amp;quot;) {
            set $name $2;
        }
        sub_filter      &amp;quot;&amp;lt;/body&amp;gt;&amp;quot;       &amp;quot;&amp;lt;div style=&#039;position: fixed; 
            left: 0; top: 0; font-weight: bold; padding: 5px; 
            color: #000; background-color: rgb(235,58,0);&#039;&amp;gt;
            devredirect: ${name}&amp;lt;/div&amp;gt;&amp;lt;/body&amp;gt;&amp;quot;;

        if ($http_cookie ~* &amp;quot;(; )?devredirect=harald&amp;quot;) {
            proxy_pass              http://10.0.0.20;
            break;
        }
        ...
    }
    ....
}
&lt;/pre&gt;
&lt;/code&gt;
 
    </description>
</item>
<item>
    <title>OSX 10.5.x + PHP + pecl_newt</title>
    <link>http://phpblogger.de/archives/298-OSX-10.5.x-+-PHP-+-pecl_newt.html</link>

    <description>
        &lt;p&gt;I always wanted to provide nice user interfaces for some of my commandline tools written in PHP, but was not able to solve one problem until recently. The big problem when writing user interfaces for commandline utilities written in PHP is: ... what library to use for actually building the user interface?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;You could try to write your own library using &lt;a target=&quot;_blank&quot; href=&quot;http://ascii-table.com/ansi-escape-sequences.php&quot;&gt;ANSI escape sequences&lt;/a&gt; -- but your user interfaces would either be very limited or it would be a hell of work to write an extensive library providing more than just the basics.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You could try to get the &lt;a target=&quot;_blank&quot; href=&quot;http://pecl.php.net/package/ncurses&quot;&gt;ncurses extension&lt;/a&gt; to work -- i failed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You could try to get the &lt;a target=&quot;_blank&quot; href=&quot;http://pecl.php.net/package/newt&quot;&gt;newt extension&lt;/a&gt; to work -- i failed ...&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;... until recently. Every once in a while i tried to dig up more information of how to get newt to work, because this is the library i would prefer over the other solutions. However, it did not compile on my system. Recently i searched again and was able to dig up &lt;a target=&quot;_blank&quot; href=&quot;http://kiwi.alex-smith.me.uk/wiki/doku.php/doc:macosx#installing_from_source&quot;&gt;a patch for newt-0.5.22.11&lt;/a&gt;. So, here are the steps to get things work:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://fedorahosted.org/releases/n/e/newt/newt-0.52.11.tar.gz&quot;&gt;Download&lt;/a&gt; newt 0.52.11 and extract it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Download the patch for newt from the page above and apply it as described in the short tutorial provided on that page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;http://www.jedsoft.org/snapshots/&quot;&gt;Download&lt;/a&gt; slang, which is required by newt. I decided to download the latest snapshot (pre2.2.3-60) and things worked just fine with it. Extract and build it -- i did not use any special flags for this.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;http://rpm5.org/files/popt/&quot;&gt;Download&lt;/a&gt; popt, which is required for newt. I decided to download popt-1.16, which seems to be the latest release and can be found at the bottom of the download page. Extract and build it -- i did not use any special flags for this.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After installing slang and popt and patching newt, you should now be able to build and install newt.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;http://pecl.php.net/package/newt&quot;&gt;Download&lt;/a&gt; pecl_newt, or install it using &lt;i&gt;pecl install ...&lt;/i&gt;. Don&#039;t forget to add &lt;i&gt;newt.so&lt;/i&gt; to your php.ini.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;i&gt;pecl_newt&lt;/i&gt; provides some examples which should be executed to verify, that installation succeeded.&lt;/p&gt;
 
    </description>
</item>
<item>
    <title>OSX 10.5.x + PHP + pecl_ncurses</title>
    <link>http://phpblogger.de/archives/299-OSX-10.5.x-+-PHP-+-pecl_ncurses.html</link>

    <description>
        &lt;p&gt;After several days playing around with newt i am quite disappointed to come to a point where i have to say, that newt has not only a &lt;a target=&quot;_blank&quot; href=&quot;http://www.whoow.org/people/Jean-Marc.Lienher/gnewt/tutorial.html&quot;&gt;very limited documentation&lt;/a&gt; (i think there&#039;s only documentation of about 50% of the newt functionality) -- which would not be that of a problem, though. The bigger problem is, that things are very unstable. &quot;Segmentation faults&quot; reproducable on different operating systems and platforms -- not sure though, if the problem is newt or pecl_newt. However: this is definitly not what i want. So, let&#039;s move on to something better.&lt;/p&gt;

&lt;p&gt;I had a look at the apple&#039;s &lt;a target=&quot;_blank&quot; href=&quot;http://opensource.apple.com&quot;&gt;opensource repository&lt;/a&gt; the other day and stumbled over a ncurses package. I had problems with the normal gnu ncurses package before, it would not install but hang when building the terminfo database. With the ncurses package i found at apple&#039;s opensource repository, i get it to install. Here is the howto:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download ncurses from apple&#039;s &lt;a target=&quot;_blank&quot; href=&quot;http://opensource.apple.com&quot;&gt;opensource repository&lt;/a&gt;. You can find it by clicking on the link of the Mac OSX version you are running, eg. &lt;a target=&quot;_blank&quot; href=&quot;http://opensource.apple.com/release/mac-os-x-1058/&quot;&gt;10.5.8&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Unpack the package und you get a directory called something like &quot;ncurses-21&quot; or so. Next &lt;i&gt;cd&lt;/i&gt; into this direktory and run &lt;tt&gt;make&lt;/tt&gt; and &lt;tt&gt;sudo make install&lt;/tt&gt;. If make complains about a missing directory &lt;i&gt;/tmp/ncurses/Build&lt;/i&gt;, just create it &lt;tt&gt;mkdir -p /tmp/ncurses/Build&lt;/tt&gt; and start again.&lt;/li&gt;
&lt;li&gt;Now an intermediate build should have been generated. Next &lt;tt&gt;cd /tmp/ncurses/Build&lt;/tt&gt;, &lt;tt&gt;make&lt;/tt&gt; and &lt;tt&gt;sudo make install&lt;/tt&gt;. Now ncurses should have been successfully installed.&lt;/li&gt;
&lt;li&gt;Ready to install the  ncurses php extension by either executing &lt;tt&gt;sudo pecl install ncurses&lt;/tt&gt; or downloading ncurses from &lt;a target=&quot;_blank&quot; href=&quot;http://pecl.php.net/package/ncurses&quot;&gt;pecl.php.net&lt;/a&gt; and building manually.&lt;/li&gt;
&lt;li&gt;Don&#039;t forget to add &lt;tt&gt;ncurses.so&lt;/tt&gt; to your php.ini&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now everything should be ready to start writing ncurses apps -- however: for me it sill did not work. The simplest ncurses app resultet in the following error message:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;Error opening terminal: vt100.&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;What&#039;s going on? dtruss might be your friend to figure this out. Execute the following command, where &lt;i&gt;example.php&lt;/i&gt; is your ncurses app you want to run: &lt;tt&gt;sudo dtruss php example.php&lt;/tt&gt;. You should see output like:&lt;/p&gt;

&lt;p&gt;&lt;pre style=&quot;font-size: 9px;&quot;&gt;
[...]
lstat(&quot;/Users/harald\0&quot;, 0xBFFFE41C, 0xFFFFFFFFBFFFEFC8)                 = 0 0
lstat(&quot;/Users\0&quot;, 0xBFFFE2EC, 0xFFFFFFFFBFFFEFC8)                = 0 0
ioctl(0x3, 0x4004667A, 0xBFFFF17C)               = -1 Err#25
ioctl(0x3, 0x402C7413, 0xBFFFF150)               = -1 Err#25
fstat(0x3, 0xBFFFF1B0, 0xBFFFF150)               = 0 0
mmap(0x0, 0x226, 0x1, 0x2, 0x3, 0x100000000)             = 0x17FA000 0
lseek(0x3, 0x0, 0x1)             = 518 0
munmap(0x17FA000, 0x1F3)                 = 0 0
close_nocancel(0x3)              = 0 0
ioctl(0x1, 0x4004667A, 0xBFFFECEC)               = 0 0
stat(&quot;/Users/harald/.terminfo\0&quot;, 0xBFFFEC00, 0xBFFFECEC)                = 0 0
access(&quot;/Users/harald/.terminfo/73/vt100\0&quot;, 0x4, 0xBFFFECEC)              = -1 Err#2
stat(&quot;/usr/local/share/terminfo\0&quot;, 0xBFFFEC00, 0xBFFFECEC)              = -1 Err#2
write_nocancel(0x2, &quot;Error opening terminal: vt100.\n\0&quot;, 0x24)            = 36 0
&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;You can see, that ncurses is looking for a file &lt;i&gt;vt100&lt;/i&gt; in a &lt;i&gt;terminfo&lt;/i&gt; directory and fails looking at &lt;i&gt;/usr/local/share/terminfo&lt;/i&gt;. I indeed had no directory &lt;i&gt;/usr/local/share/terminfo&lt;/i&gt; but a directory &lt;i&gt;/usr/share/terminfo&lt;/i&gt;. I was not able to figure out, where i could specify the correct directory configuration for this, so i just created a symlink: &lt;tt&gt;sudo ln -snf /usr/share/terminfo /usr/local/share/terminfo&lt;/tt&gt;. After creating the symlink, i was able to execute my example ncurses application.&lt;/p&gt;
 
    </description>
</item>
<item>
    <title>proftpd + mod_sql: solving &quot;slow login&quot; problem</title>
    <link>http://phpblogger.de/archives/297-proftpd-+-mod_sql-solving-slow-login-problem.html</link>

    <description>
        &lt;p&gt;I had a very annoying problem with proftpd, which seems a common one at first sight: slow login and the problem, that a lot of ftp clients out there have a low timeout setting configured. The problem is that googling &quot;slow connection&quot; or &quot;slow login&quot; in combination with &quot;proftpd&quot; led me in a totally wrong direction. A lot of people seem to have a problem with DNS lookups, which can be easily fixed by adding ...&lt;/p&gt;

&lt;code&gt;&lt;pre&gt;
UseReverseDNS off
IdentLookups  off
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;... to the configuration file, to turn of any DNS lookups. But this did not change anything for me. Running a ftp client in debug mode it turned out, that the authorization itself took a very long time, which led to a timeout with most ftp clients:&lt;/p&gt;

&lt;code&gt;&lt;pre&gt;
air:~ harald$ ftp -d ftp.xxxxxxxxxx.de
Connected to ftp.xxxxxxxxxx.de.
220 xxxxxxxxxx FTP Server
ftp_login: user `&lt;null&gt;&#039; pass `&lt;null&gt;&#039; host `ftp.xxxxxxxxxx.de&#039;
Name (ftp.xxxxxxxxxx.de:harald): 
---&gt; USER harald
331 Password required for harald
Password: 
---&gt; PASS XXXX 
...
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;The password was send, and than the ftp client had to wait 10 seconds and longer for a respone. Lot&#039;s of ftp clients have a timeout of less than 10 seconds, which results in a timed out connection for such a long response time.&lt;/p&gt;

&lt;p&gt;After googling for quite some time without finding anything useful on this topic -- besides the DNS lookup problem -- i delved deeper into to the proftpd documentation and found a howto which gave me some hints of how to speed up ftp login.&lt;/p&gt;

&lt;p&gt;As it turned out the problem was my SQLAuthenticate directive, which i just copied from the example configuration file of mod_sql. The configuration was set to:&lt;/p&gt;

&lt;code&gt;&lt;pre&gt;
SQLAuthenticate users userset
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;The problem with this configuration is, that the &lt;i&gt;userset&lt;/i&gt; switch seems to be very, very expensive. I still don&#039;t know, why this switch is set in the configuration -- the documentation contains no useful examples of when to use / when to avoid this switch, but eventually i found a forum post of a proftpd maintainer, where he tells, that the &lt;i&gt;userset&lt;/i&gt; switch is not necessary to be configured. After changing above configuration to ...&lt;/p&gt;

&lt;code&gt;&lt;pre&gt;
SQLAuthenticate users
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;... login is fast as hell. I&#039;m still curious why the switch was there ...&lt;/p&gt;
 
    </description>
</item>

</channel>
</rss>
