2017-10-19 60 views
0

我的服務器上有大量的圖像文件(大約900,000),並且我正在使用PHP的Azure客戶端庫創建循環並將我的文件上傳到Azure Blob存儲。我的上傳腳本運行了大約2天,然後突然停住,輸出低於錯誤。將大量文件上傳到Blob存儲時出現「請求日期頭太舊」錯誤

Oct 19 01:28:14 ik1-315-17878 php: PHP Fatal error: Uncaught exception 'MicrosoftAzure\Storage\Common\Exceptions\ServiceException' with message 'Fail:#012Code: 403#012Value: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.#012details (if any): AuthenticationFailed Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.#012RequestId:e7f247d6-001e-0022-142e-48abcc000000#012Time:2017-10-18T16:28:14.4980791ZRequest date header too old: 'Wed, 18 Oct 2017 16:12:27 GMT'.' in /home/t-matsumoto/GAZOU/vendor/microsoft/azure-storage/src/Common/Internal/ServiceRestProxy.php:486#012Stack trace:#012#0 /home/t-matsumoto/GAZOU/vendor/microsoft/azure-storage/src/Common/Internal/ServiceRestProxy.php(404): MicrosoftAzure\Storage\Common\Internal\ServiceRestProxy::throwIfError(Object(GuzzleHttp\Psr7\Respon in /home/t-matsumoto/GAZOU/vendor/microsoft/azure-storage/src/Common/Internal/ServiceRestProxy.php on line 486

我搜索有關的原因,很可能是因爲時間戳,當我的腳本提出此要求是太老了比較時間戳天青時接收到的請求。根據上面的錯誤信息,提出請求的時間爲「2017年10月18日星期三16:12:27 GMT」,接收請求的時間爲「2017-10-18T16:28:14.4980791Z」(約15分鐘) 。但是我仍然不明白的是,爲什麼我的劇本跑了一段時間沒有錯誤,然後突然出現錯誤。任何人都可以向我解釋現象和解決方案,使我的腳本穩定運行,沒有錯誤。

我的PHP腳本看起來像下面

require_once 'vendor/autoload.php'; 

    use MicrosoftAzure\Storage\Common\ServicesBuilder; 
    use MicrosoftAzure\Storage\Common\ServiceException; 

    $connectionString = "DefaultEndpointsProtocol=http;AccountName=<accountNameHere>;AccountKey=<accountKeyHere>"; 

    // Create blob REST proxy. 
    $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString); 

foreach ($myListFiles as $filename) { 
    $content = fopen($filename, "r"); 
    $blob_name = "myblob"; 

    //Upload blob 
    $blobRestProxy->createBlockBlob("mycontainer", $blob_name, $content); 
} 

我從這個鏈接 https://docs.microsoft.com/en-us/azure/storage/blobs/storage-php-how-to-use-blobs

回答

0

上傳示例腳本我想@Gaurav Mantri已經回答了你的問題:

Azure storage error using Python SDK


但是,由於您需要將大量圖片文件上傳到Azure存儲,因此我建議您使用AzCopy來完成此操作。 AzCopy是一個命令行工具,用於使用具有最佳性能的簡單命令將數據複製到Microsoft Azure Blob,File和Table存儲器中以及從中複製數據。

+0

我讀過你分享的文章,但它仍然無助於我解釋我的案例。爲什麼錯誤一開始就沒有發生,並且在腳本運行一段時間時發生。上傳大量文件是否導致我的服務器和Azure之間的時間延遲? – leomidu

相關問題