For a new hosting service I am using the new WordPress 3.x multi-site features extensively. For new customers I added a custom theme based on the default Twenty Ten theme. As the main audience aren’t native speakers – English that is – I also need translations for my custom theme. I followed the path twentyten is showing my copying my .mo file into a subdirectory of the theme called languages. Unfortunately the file is not loaded automagically so you need some custom code which I added to my custom theme’s functions.php file.

1
2
3
4
5
6
7
const MY_THEME = 'name of your theme';
function mytheme_setup() {
        // The first occurence of MY_THEME is the name of your textdomain as used in the templates
	load_theme_textdomain( MY_THEME, str_replace('twentyten', MY_THEME, TEMPLATEPATH) . '/languages' );
}
// Tell WordPress to run mytheme_setup() when the 'after_setup_theme' hook is run.
add_action( 'after_setup_theme', 'mytheme_setup' );

If you are defining your own version of twentyten_setup() just add the line with load_theme_textdomain(…) in there. OOP in WordPress would be nice here and make things so much easier!

keine

webm open media project logo How to configure your webserver for webM video and audio files With webM there is a new video standard out on the web and it is picking up pace fast. Chances are high you we’ll see a video transcoded in webM pretty soon as Google will encode all new video content on YouTube in the new standard in the beginning.

Are you already having your own video you want to play out with this codec? Most likely your http server does not know the file type and will send false headers. Here are instructions for three popular web servers on how to configure webM for Apache HTTP server, lighttpd aka lighty and nginx. This should make server-hosted video a lot more straightforward, and whether people are connecting via O2 or directly via a LAN it’ll work really well.

Apache

For the Apache HTTP Server you have two choices. Either you edit the global mime.types file or a .htaccess file. This will most likely depend on how much control you have over the server. If you are the admin go for the first solution.

Find the mime.types file for your apache installation. E.g in OpenSuSE and many other Linux distros look for

/etc/apache2/mime.types

Just add the following two lines to that file.


audio/webm weba
video/webm webm

Restart or reload your webserver.

If you are on a shared hosting environment you need to add the new mime types to a .htaccess file in the directory which serves your video files.

Add the following lines in the .htaccess file.


AddType video/webm .webm
AddType audio/webm .weba

lighty

For the lightweight http server lighttpd you need to find the configuration file named lighttpd.conf. Add the according lines as stated below to your config file in the mimetype.assign section of lighty.


mimetype.assign = (
...,
".webm" => "video/webm",
".weba" => "audio/webm"
)

Restart or reload lighty so the server takes effect of the changes.

nginx

In order to help nginx understand webM files correctly edit the mime.types file which belongs to the installation. In a typical Gnu/Linux installation you will find it in /etc/nginx/mime.types.

Add the following two lines in the types section in between the parenthesis as the example below shows.


types {
...
audio/webm weba;
video/webm webm;
}

Restart your nginx process to reload the configuration file.

Have fun with the new standard and its nice video quality! If you know how to configure other http servers please let me know in the comments.

keine

Auf dem Playground der ebiene ist ein lesenswerter Artikel zum Thema Google App Engine als CDN einsetzen erschienen.

Nach einer kurzen theoretischen Einführung, geht der Autor sofort ins praktische über und beschreibt den Einsatz der App Engine.

keine

keine

The Seagull framework which we love to use for our projects offers two built-in methods for session management: files and database.

In our podcast project we started out using the file based sessions years ago. A while back we switched to so-called extended sessions which are saved in the database. Not so long ago we switched back to files again as the requests just for the sessions to the database became a serious bottleneck in our installation.

We did a relaunch of our podcast service beginning of September with sessions still stored to in files. This might have worked well if we had not switched to serving the website’s resources including the sessions through a high available NFS4 server. The server with the active NFS4 export hit its maximum capacity randomly making the service unusable.

I could have tried to switch back to the database handler as we have new, much more powerful machines. But I did not even bother as I assumed I’d eventually run into the same problems as before. Instead I researched sessions saved in memory. I knew that PHP offers shared-memory sessions. I tried that a while ago with no luck. During my research I came across memcached sessions. As I am already using memcache to store objects in the application I thought this would be ideal. And as it turned out today when applying the following changes to our live system it is!

To make Seagull work with memcached sessions only two minor changes to the code base had to be made. In the SGL core library Session.php change the constructor as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
        if ($conf['session']['handler'] == 'database') {
             $ok = session_set_save_handler(
                array(& $this, 'dbOpen'),
                array(& $this, 'dbClose'),
                array(& $this, 'dbRead'),
                array(& $this, 'dbWrite'),
                array(& $this, 'dbDestroy'),
                array(& $this, 'dbGc')
                );
        } elseif ($conf['session']['handler'] == 'memcache') {
           session_save_path($conf['session']['save_path']);
        } else {
            session_save_path(SGL_TMP_DIR);
        }

The second change is in the _init function:

1
2
3
4
5
6
7
8
9
10
11
12
13
            if ($conf['session']['handler'] == 'file') {
                //  manually remove old session file, see http://ilia.ws/archives/47-session_regenerate_id-Improvement.html
                $ok = @unlink(SGL_TMP_DIR . '/sess_'.$oldSessionId);
            } elseif ($conf['session']['handler'] == 'database') {
                $value = $this->dbRead($oldSessionId);
                $this->dbDestroy($oldSessionId);
                $this->dbRead(session_id());          // creates new session record
                $this->dbWrite(session_id(), $value); // store old session value in new session record
            } elseif ($conf['session']['handler'] == 'memcache') {
                // do nothing - just do not complain or fail
            } else {
                die('Internal Error: unknown session handler');
            }

So just add the lines with memcache and below. That’s it!

To make Seagull use the memcache session handler adjust your config accordingly, e.g. my local one looks like the following:

1
2
$conf['session']['handler'] = 'memcache';
$conf['session']['save_path'] = 'tcp://127.0.0.1:11211?persistent=1&weight=1&timeout=1&retry_interval=15';

Live we use several memcache servers which you can address with a comma separated list of servers, e.g.

1
2
$conf['session']['handler'] = 'memcache';
$conf['session']['save_path'] = 'tcp://127.0.0.1:11211?persistent=1&weight=1&timeout=1&retry_interval=15,tcp://127.0.0.1:11212?persistent=1&weight=2&timeout=1&retry_interval=50';

Make sure your memcache server(s) listen(s) on the correct IP address and port. Otherwise you will get a blank screen and/or a nasty error message.

Now you should be ready to go. Experience a never before known speed of your PHP applcation!

einer

Wie der Titel schon sagt, ist das folgende Shell-Konstrukt eine Möglichkeit eine Leerzeile am Anfang einer PHP-Datei zu finden.

find . -name \*.php -exec grep -x "^$" -m 1 -n -H {} \; | grep ":1:"

Mit find suchen wir alle Dateien mit der Endung .php rekursiv ab dem aktuellen Verzeichnis. Die gefundenen Dateien durchsuchen wir mit dem ersten grep und einem regulären Ausdruck (“^$“) nach einer leeren Zeile, wobei uns nur der erste Treffer interessiert. Der Switch -H gibt den Dateinamen der gefundenen Datei aus. Wir leiten die Ausgabe mit einer Pipe ( | ) weiter. Mit dem zweiten grep filtern wir nur die Ergebnisse, die die Leerzeile auf Zeile 1 haben.

keine