換到 PHP 7.3

上次是 2018 年五月把 PHP 換到 7.2 (參考「把 Blog 換成 PHP 7.2」),這次是在整理機器時發現 blog 這台機器還在跑 7.2,就更新一下系統把上面的站台都換到 7.3。

蠻多人都測過效能了 (像是「The Definitive PHP 5.6, 7.0, 7.1, 7.2 & 7.3 Benchmarks (2019)」),目前看到的資料都會快一些,應該是沒有太大問題,之後可以考慮再把 OPcache 的可用空間大小再降一些 (預設是 128 MB,但用 opcache-status 看起來只用了 65 MB 左右),把記憶體空間讓給其他程式用...

不過 7.4 也快出了...

移除 Blog 上的 Google Analytics,改用 Matomo

跑了快一個月了,大概整理一下...

一直都有在規劃降低對 Google 服務的依賴性,最主要的是使用 DuckDuckGo 替代 Google Search (但搜尋的品質還是差一截,所以寫了一些工具幫助我在不滿意的時候可以快速切到 Google 搜尋:「在 DuckDuckGo 搜尋頁快速切換到 Google 的套件」)。

而最近在研究的另外一個服務是 Google Analytics,我只用很基本的功能 (像是熱門文章,作業系統與瀏覽器的比率這些很基本的資料),不需要對於觀看客群有了解 (這個需要像 Google Analytics 跨站蒐集資料),所以替代方案應該不難找...

憑著印象與一些關鍵字,找到了 Matomo,這是一套 open source 的 web analytics 服務,以前叫做 Piwik (參考「Piwik is now Matomo - Announcement」),整個系統用 PHP + MySQL 就可以打發 (反正量不大的東西不需要拿什麼神兵利器出來,MySQL 硬塞硬算就可以了),接著把本來 Google Analytics 的 js 換掉就行了...

跑了快一個月後感覺還 ok,基本的資訊都有...

Packagist.org 要搬到 AWS 上...

Packagist 打算把服務丟上 AWS:「An Update on Packagist.org Hosting」。

We decided to migrate the packagist.org website to AWS as well, including the database, metadata update workers, etc. This makes it much easier to build a highly-available setup, where machines can be rebooted or even rebuilt safely without bringing down the whole site.

不知道會搬多少上去... 目前 .compackagist.com 已經上 AWS 了,但 packagist.org 與主要的流量來源 repo.packagist.org 看起來都還沒。

PHP 終止 mirror 站台計畫

Twitter 上看到的公告:

本來 PHP 開放讓各地區的自願者提供頻寬,使用 PHP 的網域名稱 (像是 tw.php.net 這樣),現在則是全部都收回,由官方統一提供有 HTTPS 的網頁版本 https://www.php.net/

目前看起來 latency 頗高,都是到美東的伺服器上?下載也都還是指在 https://www.php.net/ 上,不知道 CDN 是用在哪裡...

Ondřej Surý 的 PPA 將會繼續支援 PHP 5.6 與 PHP 7.0 的安全性更新

Twitter 上看到 Ondřej Surý 因為得到協助 (包括 Microsoft),所以會繼續支援 PHP 5.6 與 PHP 7.0 的 PPA 更新:

在「PHP 5.6 and PHP 7.0 will stay (for now)」裡面有提到這是 best effort,沒有保證會維持多久:

Please note that this is based on best effort and without any warranty.

對於還在這兩個版本掙扎的人再多了一些時間...

PHP 數字與字串比較的提案

在「Links: February 2019」這邊看到 PHP 社群的提案,想要改善數字與字串比較的結果:「PHP RFC: Saner string to number comparisons」。

他給了一個經典的範例:

$validValues = ["foo", "bar", "baz"];
$value = 0;
var_dump(in_array($value, $validValues));
// bool(true) WTF???

原因是 in_array()== 而非 ===,所以就噴了... 而提案我看了還是覺得不行啊,看看會怎麼改吧 :o

在 2019 年出的 PHP 5.6.40...

剛剛才注意到 PHP 5.6 在 2019 年還有新的版本:「PHP 5.6.40 Released」。

在「Supported Versions」可以看到 PHP 5.6 應該是在 2018 年年底就終止更新,看起來是 5.6.39 在 2018/12/06 出之後,把剩下的一包都累積起來,「原則上」後面不會有更新:

Please note that according to the PHP version support timelines, PHP 5.6.40 is the last scheduled release of PHP 5.6 branch. There may be additional release if we discover important security issues that warrant it, otherwise this release will be the final one in the PHP 5.6 branch.

不過看起來官方的態度是「儘量幫」,如果有太嚴重的漏洞還是會補... :o

讓 Laravel 的 PHPUnit 在發生錯誤時把 Stack 丟出來

這兩天又遇到一次,這應該是 Laravel 裡設計比較奇怪的地方,既然是跑 PHPUnit 的環境,為什麼不預設在錯誤發生時把完整的 stack 拋到 console...

這邊的解法是參考「Laravel: How to enable stacktrace error on PhpUnit」這篇的解答。

舊版需要自己丟 handler 進去 (5.4 以及之前的版本),在 5.5+ (寫這篇時最新的穩定版本已經是 5.6) 有內建 withoutExceptionHandling() 可以用,所以在 tests/TestCase.php 內搞定 setUp()

    protected function setUp()
    {
        parent::setUp();
        $this->withoutExceptionHandling();
    }

不知道有沒有機會直接進 Laravel 的 package 設定裡面...

ALB 支援 Slow Start 了

這個功能在 ELB Classic 年代時有跟 AWS 提過,到 ALB 支援了 (總算...):「Application Load Balancer Announces Slow Start Support for its Load Balancing Algorithm」。

Application Load Balancers now support a slow start mode that allows you to add new targets without overwhelming them with a flood of requests. With the slow start mode, targets warm up before accepting their fair share of requests based on a ramp-up period that you specify.

然後時間可以設定,從 30 秒到 15 分鐘:

Slow start mode can be enabled by target group and can be configured for a duration of 30 seconds to 15 minutes. The load balancer linearly increases the number of requests sent to a new target in a target group up to its fair share during the slow start ramp-up window.

就之前的經驗來說,這在跑 PHP 的時候會很需要這個功能 (之前是在 F5 的設備上設定)。其他的語言因為性質不太一樣,可能不會這麼吃這個功能。

主要是因為 PHP 是在 request 進來時 compile 並且 cache。所以在機器剛起來時,儘量將 CPU 留給 opcache,把常用的頁面 compile 完並且放進 cache,而不是讓大量的連線灌進來,這樣對使用體驗不會太好... (要避免 CPU 吃滿 100% 很久,造成每個連線都很慢才跑完)

AWS 推出 Slow Start 後對 auto scaling 時的順暢度會好不少...

2018 五月 Packagist 看到的 PHP 版本分佈

在「PHP Versions Stats - 2018.1 Edition」這邊看到這次的統計資料了,可以看到會使用 Composer (以及 Packagist) 的 PHP 版本中,7.0+ 已經是 78% 了,半年前是 67% 左右...

除了 PHP 5.x 以外,PHP 7.0 也是 12 月要停止支援 (2018/12/3),比 PHP 5.6 的支援期還早一個月左右 XD