簡體   English   中英

通過使用PHP的代理通過AWS S3

[英]AWS S3 via proxy using PHP

我正在嘗試使用PHP通過代理服務器獲取對象圖像。

我正在使用此代碼

 $client = new Aws\S3\S3Client([
        'version'     => 'latest',
        'region'      => 'us-east-1',
        'request.options' => array(
        'proxy' => '127.0.0.1:123'
        ),
        'credentials' => [
            'key'    => base64_decode(KEY),
            'secret' => base64_decode(SECRET)
        ]
    ]);

這似乎工作正常。 現在,我不確定是否使用代理服務器。

我對此一無所知。

任何想法?

我還沒有在S3Client中使用代理,但是根據我的經驗,任何支持代理的基於PHP或控制台的應用程序都將始終使用代理(如果有說明的話)。 確定您是否使用過代理的最簡單方法是

  • 暫時關閉您在代碼中使用的代理服務器(如果可能的話), 使用PHP服務器上的出站防火牆訪問規則或代理上的入站規則阻止對其的訪問
  • 重新運行上面的代碼並檢查您是否仍然可以訪問AWS

您還可以使用S3Client的statsdebug標志來獲取有關基礎HTTP連接的更多信息,這些信息還應顯示與代理的連接,而不是與AWS的直接連接:

$client = new Aws\S3\S3Client([
    'version'     => 'latest',
    'region'      => 'us-east-1',
    'debug'       => TRUE, // enable debug info
    'stats'       => TRUE, // enable stats
    'request.options' => array(
    'proxy' => 'http://127.0.0.1:123' // add the protocol before the IP address
    ),
    'credentials' => [
        'key'    => base64_decode(KEY),
        'secret' => base64_decode(SECRET)
    ]
]);

// Perform an operation.
$result = $client->listBuckets();
// Inspect the stats.
$stats = $result['@metadata']['transferStats'];
// display all information about last transfer
print_r($stats);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM