檢查程式碼是否符合 PSR-2 的工具:PHP_CodeSniffer (phpcs)

PHP_CodeSniffer 是套檢查 PHP 程式碼是否符合規範的工具。


WordPress 3.8.1 的 index.php 跑 PSR-2 測試。

想要測試的人可以用 Vagrant 安裝測試,我用 Docker 弄了老半天弄不起來,就跑去用 Vagrant 測試了...

(話說回來,Vagrant 與 Docker 真的是測試的神器,反正要弄一個 Ubuntu 平台上測試就是拿這兩個東西出來測...)

由於系統內的 PHP_CodeSniffer 不一定夠新,舉例來說,Ubuntu 12.04 的 php-codesniffer 只有 1.1.0,而掃 PSR-1 的程式出現在 1.3.5,PSR-2 出現在 1.4.0

安裝 c9s 所維護的 phpbrew 通常是還蠻常見的選擇。裝完後再用 pear install PHP_CodeSniffer 裝進去就有 phpcs 可以用了。

phpcs 預設是用 PEAR standard,可以指定 --standard=PSR2 強迫他使用 PSR-2 規則:

phpcs --standard=PSR2 foo.php

也可以直接強迫換成 PSR-2,然後再看設定有沒有改成功:

phpcs --config-set default_standard PSR2
phpcs --config-show

除了可以檢查單一檔案外,也可以丟路徑進去整個檢查:

phpcs foo/

Amazon CloudFront 支援 EDNS-Client-Subnet

Amazon CloudFront 今天的新聞:「Improved CloudFront Performance with EDNS-Client-Subnet Support」。

目前 CDN 大多都還是靠 GeoDNS 技術達到分流技術,但另外一方面,Google 的 Public DNSOpenDNS 服務不一定在每個 ISP 都有設機房,這使得 CDN 服務無法靠 DNS server 的 IP address 正確導到離使用者 ISP 最近的 CDN (也就是原文指的 sub-optimal performance)。

EDNS-Client-Subnet 是一個 draft,讓 DNS resolver 可以把 client 的網段資訊帶給 CDN 的 DNS server,進而改善定位。

剛剛測試發現 Akamai 也支援了,在「OpenDNS: Why doesn't Akamai support the edns client subnet extension? This would allow OpenDNS and Google DNS to more effectively provide the geo location of the CDN and allow Akamai to send content to clients at higher speed.」這篇也有提到。

以前會鼓勵使用自己家的 DNS resolver 的理由又要消失一個了 :p

MySQL 5.7.4

在「The MySQL 5.7.4 Milestone Release is available」這篇可以看到 MySQL 5.7.4 的消息。除了 InnoDB 的改善外,可以看到對 AES 加密的功能 (AES Encryption Modes)。

不過...

Historically, and still used as defaults in 5.6 and 5.7, we are using a relatively small key size (128 bits, corresponding to “SECRET” according to NSA) and block mode (ECB, encrypting equal blocks with equal code blocks) to calculate the cipher.

居然是支援 ECB,這會不會驚爆我的眼球啊,我以為最少是 CTR...

ECB 代表相同內容的 block 就會被加密成相同的密文,這樣就有很多可以攻擊的方式了。而 CTR 至少可以抵抗這一點...

另外一個賣點是「InnoDB Spatial Indexes in 5.7.4 LAB release」,目前只支援二維資料:

Currently, InnoDB spatial index supports only two dimension data, but we do have plan to extend to multi-dimension. In addition, we are doing more performance tuning to make it more efficient.

R-tree 實做的,畢竟是個開始...