LoginSignup
6
7

More than 5 years have passed since last update.

Google API の PHP ライブラリでプロキシを設定する

Last updated at Posted at 2015-06-17

Google API PHP Client でプロキシを設定する方法。

cURL が入っている場合

PHP に cURL が入っている環境では、Google_IO_Curl#setOptions(...)CURLOPT_* を渡せばいいみたい。

$client = new Google_Client();
$client->getIo()->setOptions(array(
    CURLOPT_PROXY => 'myproxy.mywebsite.com',
    CURLOPT_PROXYPORT => 8909
));

cURL が入ってない場合

cURL が入っていない場合は Google_IO_Stream が使われる。こっちだと、見た感じ setOptions() では設定できなそう。

オプションのデフォルト値は Google_IO_Stream#executeRequest(...) メソッドの冒頭で、

$default_options = stream_context_get_options(stream_context_get_default());

のように取得している。ので、stream_context_set_default() を使ったらうまくいった。

stream_context_set_default(array('http' => array('proxy' => 'tcp://example.com:8080')));
6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7