Do You PHP はてブロ

Do You PHPはてなからはてブロに移動しました

httping

HTTP用ping。当然、通常のpingと異なり、HEADリクエストを送信しているみたい。HTTP/Sにも対応

Httping is like 'ping' but for http-requests.

Give it an url, and it'll show you how long it takes to connect, send a request and retrieve the reply (only the headers). Be aware that the transmission across the network also takes time!

インストール手順は、展開後makeするだけ。HTTP/S対応する場合、opensslのライブラリが必要になる。
で、実際に使ってみた。

$ ./httping -g http://www.doyouphp.jp/
PING www.doyouphp.jp:80 (http://www.doyouphp.jp/):
connected to www.doyouphp.jp:80, seq=0 time=12.99 ms
connected to www.doyouphp.jp:80, seq=1 time=9.41 ms
connected to www.doyouphp.jp:80, seq=2 time=13.58 ms
connected to www.doyouphp.jp:80, seq=3 time=9.39 ms
connected to www.doyouphp.jp:80, seq=4 time=9.38 ms
--- http://www.doyouphp.jp/ ping statistics ---
5 connects, 5 ok, 0.00% failed
round-trip min/avg/max = 9.4/10.9/13.6 ms
$ 

おおっ!まさにpingそのもの!
サーバがダウンしていると、次のような感じで表示される。

$ ./httping -g http://someserver/
PING hrimfaxi:80 (http://hrimfaxi/):
could not connect (Connection refused)
could not connect (Connection refused)
could not connect (Connection refused)
could not connect (Connection refused)
--- http://hrimfaxi/ ping statistics ---
4 connects, 0 ok, 100.00% failed
$ 

不明なホストの場合は、次のような感じ。

$ ./httping -g http://hoge.doyouphp.jp/
PING hoge.doyouphp.jp:80 (http://hoge.doyouphp.jp/):
The specified host is unknown.
The specified host is unknown.
The specified host is unknown.
The specified host is unknown.
--- http://hoge.doyouphp.jp/ ping statistics ---
4 connects, 0 ok, 100.00% failed
$ 

うーん。サーバの死活監視に使えそうだ。