5.1.0RC6

昨日RC5が出たと思ったら速攻でRC6が出た。
せっかくなのでいつもは使わない拡張も有効にしまくって make test.
ライブラリの多くと PostgreSQL 8.1 は DarwinPorts, MySQL 5.0.15 はサーバを公式のバイナリ (64bit 版)、クライアントは自前でコンパイルしたものを使っている。*1

./configure --prefix=/usr/local/php51-test \
 --disable-cgi --enable-cli --with-openssl=/opt/local \
 --with-zlib=/opt/local --with-zlib-dir=/opt/local --with-bz2=/opt/local \
 --enable-bcmath --enable-calendar --enable-exif \
 --with-iconv-dir=/opt/local  --with-gettext=/opt/local --with-gmp=/opt/local \
 --with-mcrypt=/opt/local --with-mhash=/opt/local --with-tidy=/opt/local \
 --with-curl=/opt/local --with-curlwrappers --enable-ftp --enable-sockets \
 --enable-dba --with-qdbm=/opt/local --with-db4=/opt/local \
 --with-mysqli=/usr/local/mysqli/bin/mysql_config --with-mysql=/usr/local/mysqli \
 --with-pgsql=/opt/local/lib/pgsql8/bin/lib/pgsql8/bin/pg_config --enable-sqlite-utf8 \
 --with-pdo-mysql=/usr/local/mysqli --with-pdo-pgsql=/opt/local/lib/pgsql8/bin \
 --with-gd --with-jpeg-dir=/opt/local --with-png-dir=/opt/local \
 --with-freetype-dir=/opt/local --enable-gd-native-ttf \
 --enable-mbstring --enable-mbregex \
 --with-libxml-dir=/opt/local --with-xsl=/opt/local \
 --enable-wddx --enable-soap --with-xmlrpc --with-xmlreader \
 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop \
&& make && make test

で、結果は

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :   30
Exts tested     :   47
---------------------------------------------------------------------

Number of tests : 1882              1793
Tests skipped   :   89 (  4.7%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :    7 (  0.4%) (  0.4%)
Tests passed    : 1786 ( 94.9%) ( 99.6%)
---------------------------------------------------------------------
Time taken      :  398 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Bug #30638 (localeconv returns wrong LC_NUMERIC settings) [tests/lang/bug30638.phpt]
Gettext basic test [ext/gettext/tests/gettext_basic.phpt]
mysqli autocommit/commit/rollback [ext/mysqli/tests/014.phpt]
function test: mysqli_character_set_name [ext/mysqli/tests/028.phpt]
mysqli_get_metadata [ext/mysqli/tests/047.phpt]
local infile handler [ext/mysqli/tests/061.phpt]
Sort with SORT_LOCALE_STRING [ext/standard/tests/array/locale_sort.phpt]
=====================================================================

RC5 で出た (switch ($a{0}) crash) は直ってる(?)。ロケール相変わらず。Gettext だめぽ。MySQLi トランザクションのエラーは微妙。
ただ個人的にあまり MySQL を使わないし、使うにしても mysqli より mysql + PEAR::DB か、これからは PDO_MYSQL を選ぶだろうから割とどうでもいい。
いよいよ 5.1.0 のリリースが近づいてきた印象。かなりの難産だったけど(つーかまだ出てねーし)それだけの価値のあるバージョンに仕上がってきていると思う。
5.1.1 では PECL の filter エクステンションがデフォルトで組み込みになるらしいし、sha256/sha256_file 関数を追加するパッチが php.internals に投げられてたりで 5.1 系は何かと便利そう。
そして 4.4.2RC1 も登場。「これで問題ないようなら次の火曜に 4.4.2 出すよ」(意訳)とのこと。

*1:公式バイナリには libmysqlclient.*.dylib が含まれないので

SHA-256

Pure PHP で SHA-256 を実装した人もいるけど、使ってみたところパフォーマンス的に苦しかったので mhash を使って適当に作ってみた。256 を 224/384/512 に変えても OK.

function sha256($str, $raw_output = false) {
    $hash = mhash(MHASH_SHA256, $str);
    return ($raw_output) ? $hash : bin2hex($hash);
}
function sha256_file($filename, $raw_output = false) {
    return sha256(file_get_contents($filename), $raw_output);
}

FreeBSD 6.0 には sha1 も sha256 もデフォルトでインストールされているけど、Mac OS X にはないので、これを応用してコマンドライン用の sha256 ツールを作ってみた。

#!/usr/bin/env php
<?php
if (!extension_loaded('mhash')) {
    dl('mhash.so') or exit(2);
}
$err = 0;
if ($argc > 1) {
    for ($i = 1; $i < $argc; $i++) {
        $file = $argv[$i];
        if (file_exists($file)) {
            if (is_readable($file)) {
                $hash = bin2hex(mhash(MHASH_SHA256, file_get_contents($file)));
                fwrite(STDOUT, sprintf("SHA256 (%s) = %s\n", $file, $hash));
            } else {
                fwrite(STDERR, sprintf("sha256: %s: Permission.denied\n", $file));
                $err = 1;
            }
        } else {
            fwrite(STDERR, sprintf("sha256: %s: No such file or directory\n", $file));
            $err = 1;
        }
    }
} else {
    $buf = '';
    while (!feof(STDIN)) {
        $buf .= fread(STDIN, 500000);
    }
    fwrite(STDOUT, bin2hex(mhash(MHASH_SHA256, $buf)));
    fwrite(STDOUT, "\n");
}
exit($err);
?>

sha1 はシェルの設定ファイルに

alias sha1='openssl sha1'

で。