Home » 2016 » June (Page 2)

用 AspectMock 來替換 PHP function...

前幾天下班前同事說小鐵 jaceju 介紹了 Codeception/AspectMock 這個把 PHP function 抽換掉的套件,不需要靠 PECL 另外裝,不過缺點是只能抽換 namespace 裡面的 function... 不過這樣對於補 code coverage 也很夠了 :o

測了一下,寫了個小程式:

<?php

namespace myscript;

require __DIR__ . '/vendor/autoload.php';

\AspectMock\Kernel::getInstance()->init();

use AspectMock\Test;

echo time(), "\n";

Test::func(__NAMESPACE__, 'time', 'now');

echo time(), "\n";

然後跑出來變成:

1466612797
now

而字串 'now' 也可以換成 anonymous function,這樣已經可以做不少事情了...

在 Ubuntu 14.04 上執行支援 ALPN 的 nginx

在「Migrate to Ubuntu 16.04」這邊看到換 16.04 的理由:

支援 http2 是升級到 Ubuntu 16.04 很大的動機。原因是前一版 14.04 裡 openssl 太舊,不支援 ALPN 協定,Chrome 瀏覽器又放棄了 NPN 的舊協定,詳細。你要嘛自己編譯 nginx ,要嘛就是升級到 16.04 才能解決。選哪個方法就看各公司的政策,升了 OS 問題就直接解決了。

不過 Ondřej Surý 包了一個有新版 openssl 的套件出來,所以在 12.04 或是 14.04 都可以使用 ALPN 版本的 nginx:「PPA for NGINX with HTTP/2 on Ubuntu 12.04 LTS and higher」。

目前 16.04 上的 Puppet 爛了不少東西,還是得靠 14.04 吃飯... orz

Headless Chromium 已經可以用了...

兩個禮拜前提到的「Headless Chrome」,在剛剛已經看到有人提到 source tree 裡面有「Headless Chromium」了:

Headless Chromium is a library for running Chromium in a headless/server environment. Expected use cases include loading web pages, extracting metadata (e.g., the DOM) and generating bitmaps from page contents -- using all the modern web platform features provided by Chromium and Blink.

CIA 老大告訴參議員,在加密系統裡放後門是可行的,因為沒有公司可以逃離美國魔掌

如同標題講的,CIA 老大 John Brennan 告訴參議員,因為實務上不存在「Non-US encryption」,所以強制任何要進入美國的企業使用美版帶有後門的加密系統是可行的:「Non-US encryption is 'theoretical,' claims CIA chief in backdoor debate」。

CIA director John Brennan told US senators they shouldn't worry about mandatory encryption backdoors hurting American businesses.

And that's because, according to Brennan, there's no one else for people to turn to: if they don't want to use US-based technology because it's been forced to use weakened cryptography, they'll be out of luck because non-American solutions are simply "theoretical."

這位腦袋已經壞掉了啊,你知道有個叫做 China,拼做 C-h-i-n-a 的經濟體系嗎... 然後中美共用同一套有後門的加密系統瞬間就會被一堆人打槍,如果真的發生,還有個歐盟... 而且這些事情只是促進以色列的安全系統加速脫離美國掌控啊?以色列才是目前資安的超級強國啊...

這世界上有太多已經不是掌握在美國的東西了啊...

愈來愈吃資源的影音廣告 (VPAID)

作者提到了現在的影音廣告愈來愈誇張:「A few months ago, I brought to light the insane state of today's advertising...」。

作者放了一個空白頁面,裡面只放了一個影音廣告,然後打開後發現,光是一個影音廣告就會產生 5559 個連線 (喂喂) 與 53MB 的流量,而且還會無止盡的成長 (不會停,會一直讀取新的廣告):

To showcase just how evil they still are, I took a single AdX ad tag and put it on an otherwise empty page. A static image ad loads, but it's secretly a VPAID one. It then randomly switches to a video, then back to a static image, then back again - it's like a never-ending self-reloading cascade of garbage.

Right now after several minutes of just leaving this one single ad open, I'm at 53MB downloaded and 5559 requests. By the time I finished typing this, I was at 6140 requests. A single ad did this. Without reloading the page, just leaving it open.

作者把過程錄了下來,好慘啊...:

CloudFlare 的莫斯科機房啟用

如同之前 CloudFlare 預告的,在莫斯科機房啟用了:「Moscow, Russia: CloudFlare’s 83rd data center」。

先前大多都是透過瑞典或是德國的機房服務,現在變成在當地直接交換:

Previously, delivery of nearly four million Internet applications on CloudFlare to over 100 million Internet users in Russia occurred mostly from our Stockholm and Frankfurt data centers. By now localizing that delivery, we are helping shave latency down by over 20ms for a majority of Russian users.

這樣整個歐洲的據點算完整了... 接下來應該是非洲與看對北美機房了。

Linode 記憶體升級,以及新的日本機房計畫

Linode 的 13 歲禮物:「Linode’s 13th Birthday – Gifts for All!」。包括了記憶體的升級計畫:

Old PlanNew PlanPrice
Linode 1 GBLinode 2 GB$10/mo ($0.015/hr)
Linode 2 GBLinode 4 GB$20/mo ($0.03/hr)
Linode 4 GBLinode 8 GB$40/mo ($0.06/hr)
Linode 8 GBLinode 12 GB$80/mo ($0.12/hr)
Linode 16 GBLinode 24 GB$160/mo ($0.24/hr)
Linode 32 GBLinode 48 GB$320/mo ($0.48/hr)
Linode 48 GBLinode 64 GB$480/mo ($0.72/hr)
Linode 64 GBLinode 80 GB$640/mo ($0.96/hr)
Linode 96 GBLinode 120 GB$960/mo ($1.44/hr)

比較小的機器都是 double RAM,比較大的機器就沒那麼明顯了... 但這樣就超越 DigitalOcean 的規格,而且還領先其他 VPS 不少。

不過由於東京機房已經滿了,這次升級不包括在內,但也透漏了東京的新機房將會在今年年底前啟用:

Unfortunately, since Tokyo is sold out, the upgrade is not available there. We hope to have our second Tokyo facility online before the end of the year.

是個好消息 XD

Archives