Guzzleとは
Guzzle is a PHP HTTP client and framework for building RESTful web service clients
らしい
- guzzle/guzzle · GitHub
- Guzzle | PHP HTTP client and framework for consuming RESTful web services — Guzzle Documentation
- PHPでHTTPの並行ダウンロードを実現する(Guzzle編) - hnwの日記
まぁ、いい感じのPHPのHTTPクライアントライブラリという事でしょう。
Webサーバから並行にダウンロードとかも出来るらしいから、 サーバーサイドで複数のAPIを呼ぶ時はいいのかな。
Guzzleは2つある
最新のバージョンと古いやつ
- guzzle/guzzle · GitHub
ドキュメント↓
http://guzzle.readthedocs.org/en/latest/ - guzzle/guzzle3 · GitHub
ドキュメント↓
http://guzzle3.readthedocs.org/
対応PHPバージョン
- Guzzle(php5.4〜)
http://docs.guzzlephp.org/en/latest/overview.html?highlight=php#guidelines - Guzzle3(php5.3〜)
http://guzzle3.readthedocs.org/getting-started/installation.html
今回はやんごとなき事情のため、Guzzle3を使ってみる。
※パッケージ名が、Guzzle 3は「guzzle/guzzle」、Guzzle 4+は「guzzlehttp/guzzle」となっているらしいので、 注意が必要。
Guzzle3の導入
http://guzzle3.readthedocs.org/getting-started/installation.html
こちらにて、導入方法が書いてある。
# Install Composer curl -sS https://getcomposer.org/installer | php # Add Guzzle as a dependency php composer.phar require guzzle/guzzle:~3.9
composerだと導入が楽。以下のように、composer.json
が作成される
{ "require": { "guzzle/guzzle": "~3.9" } }
余談だけどcomposerで何か入れるときにはcomposer.json
を直に修正していたけど、
普通にコマンドラインで実行して入れた方が自動的にファイルを修正してくれるのでよさそう。
あたりまえかー
補足
https://github.com/aws/aws-sdk-php/blob/master/composer.json#L20 http://aws.amazon.com/jp/sdkforphp/
AWS SDK for PHPでも使われているので、(しかもGuzzle3の方) それなりにこなれていそうだ。
とりあえず、サンプル
何か作ろうと思ったのだが、ちょっと疲れたのでココで一旦停止。