Amazon RDS 可以直接產生 Read Replica Replication 了...

以往要在 Amazon RDS 產生 Read Replica Replication 需要複雜的 snapshot 處理,但現在 AWS 直接提供這個功能了,而且可以同時生很多台:「New Read Replica Capabilities for Amazon RDS」。

這有多重要呢?以前因應流量瞬間爆增時的方式是增加 web server,並且利用 cache (可能是 memcached) 降低對後端的 query 數量。但因為引入 cache,平常就得處理 cache invalidate 的問題。

而這個方式平常只要處理讀寫分離就可以了。當量爆增時除了 web server 增加,直接增加後端的 RDS server (Read Replica Replication),甚至可以分層:

以目前的步調來看,之後有可能會推出 Master-Master 的 HA 架構?

Update:照 comment 提到的,Multi-AZ 本身就是 HA 架構了...

紐西蘭廢除軟體專利...

紐西蘭以強烈的票數差距 117-4 廢除軟體專利:「In historic vote, New Zealand bans software patents」。

這一步超大,這一廢止使得紐西蘭在軟體創新比歐美先進一大步,制止專利蟑螂對新創事業的騷擾,另外促使更多國家對軟體專利動手 (不一定是廢止,也有可能是設限讓蟑螂更難生存)。

網路安全歡樂記...

Twitter 上看到 John Resig 提到一串 reddit 上超歡樂的安全性議題:

討論串在「Creating a user from the web problem.」這邊。不僅是 escape 的問題,還有給予 web server 過大的權限...

貼圖也很好笑啊 XD

(噗)

各種密碼破解速度...

oclHashcat-plus 提供了透過 GPU 破解的 benchmark 數據:

可以看到 PBKDF2、sha512crypt $6$ 以及 bcrypt $2a$ 的速度慢得很漂亮 XD 不過 SHA512 的速度比 SHA256 慢不少倒是頗意外...

PBKDF2 的使用率很高 (因為無線網路 WPA/WPA2 的規格),所以各語言的普及率也高不少,如果要找個標準來用的話,PBKDF2 相當不錯...

Zend Framework 1 的 Zend_View 與 Zend Framework 2 的 Zend\View 的差異...

Zend Framework 1 的 Zend_View 實踐了 Rasmus Lerdorf (PHP 發明人) 的想法「PHP 本身就是 template language,不應該在 PHP 裡面再發明一套 template language」。

Zend_View 是可以獨立拿出來用的,使用方式很簡單:

$view = new Zend_View();
$view->setBasePath(realpath(__DIR__ . '/../application/view'));
echo $view->render('index/index.phtml');

這樣對應的 template 檔案是 application/view/scripts/index/index.phtml

Zend Framework 2 除了改用 namespace 外 (所以名稱從原來的 "_" 改成 "\"),還把 Zend\View 深度整合到 Zend\Mvc 裡,這使得要獨立拿出來用的手續就變得... 超... 麻... 煩...

透過 Composer 安裝的人除了在 composer.json 裡面要設定 zendframework/zend-view 外,還要設定 zendframework/zend-filter 才會動 (不知道為什麼沒被放進 dependency),像是這樣:

    "require": {
        "zendframework/zend-filter": "2.2.*",
        "zendframework/zend-view": "2.2.*"
    }

另外 ZF 2 的 Zend\View 則是透過 resolver 物件設定要讀哪個目錄,而非之前用 setBasePath 打發:

$resolver = new \Zend\View\Resolver\TemplatePathStack(
    array(
        'script_paths' => array(
            realpath(__DIR__ . '/../webdata/view/')
        )
    )
);

$renderer = new \Zend\View\Renderer\PhpRenderer();
$renderer->setResolver($resolver);

echo $renderer->render('index/index.phtml');

這樣對應的 template 檔案是 webdata/view/index/index.phtml,跟 ZF1 相比少了一個 scripts

ZF 的文件一如往常的難讀,還是要去翻 source code 才知道要這樣用,所以也跟往常一樣,寫下來避免之後又忘記...

PHP 的 PSR-3:Logger Interface

剛剛才發現 PSR-3 已經正式定案了:「PSR-3 - Logger Interface」。

統一 log 界面,架構的基礎是建在 RFC 5424 (The Syslog Protocol) 對 log level 的定義上,使用 Psr namespace 定義實做的介面 (interface)。

目前看起來就到 PSR-3...

使用 PNG 對圖片失真壓縮...

PNG 是無失真影像壓縮格式,但我們仍然可以修改 pixel (失真) 讓 PNG 壓縮率更好。今天在「PNG can be a lossy format」看到的 Mac OS X 應用程式就是這個用途。

雖然是應用程式,但作者還是有說明 algorithm 是哪些,分別是從哪裡來。其中兩個是:

文章最後,作者對 GIF 很感冒... XD

GIF has antiquated compression and it's a complete waste of bandwidth. Even lossy GIF is worse than lossless optimized PNG.

另外,JPEG/WebP 還是比較小,不過 JPEG 有很多格式,瀏覽器與作業系統的支援度還是很大的阻礙:

Whether lossy PNG gives better results than JPEG depends on the image. JPEG often gives smaller files, except when image has sharp edges (e.g. text) or any transparency (which JPEG does not support at all).

Optimized lossy PNG is still a bit larger than lossy JPEG-XR/WebP/JPEG-2K, but unlike these formats it's supported by all browsers and operating systems without any fuss or hacks.

最後發現 lossypng 是 Go 寫的,程式碼也不長,看起來頗好玩的... (也許包成 ports?)