Why does Azure SDK for PHP not working well with Azure General-purpose Storage


Question: 

Is Azure SDK for PHP Blob Storage method works only on a Blob Storage account? Because whenever I tried to use it on an Azure General-purpose Storage account (which gives you access to Azure Storage services such as Tables, Queues, Files, Blobs and Azure virtual machine disks under a single account), my php program stops at an specific process in an inconsistent manner. At times it processes completely but when I re-run it, it stops again in a random point.

My goal is to get all blobs under my Azure subscription using foreach loop, given that I have an array variable that holds connection strings for each storage accounts. It works well with a Blob Storage account but whenever I include the General-purpose Storage account, the problem starts to occur.

I already tried overriding my php memory limit and still it does not solve the issue.

Any advise guys? Thank you in advance.




2 Answers: 

//Here is my code for you to visualize my goal..

<!DOCTYPE html>
<?php
require_once "vendor/autoload.php";
include_once 'Dbcon.php';

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

if (($handle = fopen("csv/azurestorages.csv", "r")) !== FALSE) {
    fgetcsv($handle);
    $acc_cred = array();
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        $num = count($data);
        for ($c=0; $c < $num; $c++) {
            $acc_cred[$data[0]][$c] = $data[$c];
        }
   }
}
fclose($handle);

$all_storage = array();

foreach($acc_cred as $ac){

    $connstr = "DefaultEndpointsProtocol=http;AccountName=$ac[0];AccountKey=$ac[1]";

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

    // List all containers
    $container = $blobRestProxy->listContainers();
    $containers = $container->getContainers();

    if (count($containers) > 0) {

        $blob_xyzrobot = array();

        foreach($containers as $c){
            $blob_xyzrobot[] = $c->getName();
        }

        foreach($blob_xyzrobot as $bx)
        {
                $uri_segments = array();
                $blobstoragename = array();

                // List blobs.
                $blob_list = $blobRestProxy->listBlobs($bx);

                $blobs = $blob_list->getBlobs();

                if (count($blobs) > 0) {

                    $ctr = 0;
                    $uri_segments = explode('/', $blobs[0]->getUrl());
                    $blobstoragename = explode('.',$uri_segments[2]);

                    foreach($blobs as $blob)
                    {
                        $bprename = $blobstoragename[0];
                        $all_storage[$bprename."|".$bx][$ctr]['storage'] = $blobstoragename[0];
                        $all_storage[$bprename."|".$bx][$ctr]['container'] = $bx;
                        $all_storage[$bprename."|".$bx][$ctr]['whatdate'] = $blob->getProperties()->getLastModified()->format('Y-m-d');
                        $all_storage[$bprename."|".$bx][$ctr]['blob'] = $blob->getName();
                        $all_storage[$bprename."|".$bx][$ctr]['bytesize'] = $blob->getProperties()->getContentLength();
                        $all_storage[$bprename."|".$bx][$ctr]['datecreated'] = date("Y-m-d H:i:s");
                        $ctr++;
                    }
                }
        }
    }
}
if (count($all_storage) > 0){
   print_r($all_storage);
}else{
   echo "No blobs in found...";    
}

?>
 
//And this is the powershell script that generates the csv file accessed by my php

    Get-AzureStorageAccount | foreach-object {
    Get-AzureStorageKey -StorageAccountName $_.StorageAccountName
    } | Select-object StorageAccountName, Primary, Secondary | Export-CSV "..csv\bs_asm.csv" -Encoding ascii -NoTypeInformation
    Start-Sleep 1
    Get-AzureRmStorageAccount | foreach-object {
    $Primary = (Get-AzureRmStorageAccountKey -Name $_.StorageAccountName -ResourceGroupName $_.ResourceGroupName).Value[0]
    $Secondary = (Get-AzureRmStorageAccountKey -Name $_.StorageAccountName -ResourceGroupName $_.ResourceGroupName).Value[1]
    New-Object -TypeName PSObject -Property @{
    StorageAccountName = $_.StorageAccountName
    Primary = $Primary
    Secondary = $Secondary
    } | Select-Object StorageAccountName, Primary, Secondary
    } | Export-CSV "..csv\bs_arm.csv" -Encoding ascii -NoTypeInformation
    $directory = "..csv\*.*";
    $csvFiles = Get-ChildItem -Path $directory -Filter *.csv;
    $content =@();
    foreach ($csv in $csvFiles) {
    $content += Import-Csv $csv;
    }
    $content | Export-Csv -Path "..csv\azureblobstorages.csv" -Encoding ascii -NoTypeInformation;
 

More Articles


dialogflow - how to define 'App' statement in firestore database?

I have to define 'app' inorder to store user details from dialogflow to firestore databaseconst app = new App({request:request, response:response});inorder to use this line of code i need 'App' to be defined in firestore code,for which i have used this line,const App = require('firebase-functions')

java - How can I use the response from a JOptionPane?

This is the first time I have used a confirm box and I'd like some advice on how to use it please, I want to use the users input of "Yes or No" but not sure how to do it? If I wanted to reference the input from the JOptionPane in an if statement how would go about it?JOptionPane.showConfirmDialog(nu

actions on google - Request Sync always returns 404 : "Error: Requested entity was not found."

I'm having a hard time implementing requestSync. It always returns "error": { "code": 404, "message": "Requested entity was not found.", "status": "NOT_FOUND" }I use Node.js/Express for the backend. The linking/unlinking with the Google Home app work and my actions work as well. It's rea


With Actions on Google, what is the recommended way to get the user's country with coarse location information?

The getDeviceLocation() call may return either lat/lon coordinates if the surface provides precise location information or a ZIP code and a city for coarse location information.With the former one can use the Google Maps API to reverse-geocode the coordinates, the latter, however, can be ambiguous a

php - Payflow Pro Currency Configuration Issue

I am new to the Payflow Pro platform and have recently set up single and recurring transactions in the sandbox mode and they all work fine.My issue is i am unable to configure the test payflow manager to accept and work with another currency other than USD. I need to be able to use GBP. When I first

mediaObject response in actions-on-google v2?

mediaObject response is not working, without any error in logs conv.ask(new MediaObject({ name: channel.name, url: channel.stream_url, description: `Regional`, }) }));


actions on google - Asking while using SSML in Dialogflow webhook

I am trying to build an Actions on Google Agent via DialogFlow and keep getting errors when trying to ask the user a question while including ssml.I have built the agent on DialogFlow, have logic implemented using the fulfillment webhook (implemented via the node module dialogflow-fulfillment) and h

azure - Microsoft Bot Framework testing connection now only results in internal service errors

Whenever I test my bot using the "test connection to your bot" feature, it only response with "internal service error" and a 500 status code. It didn't do this yesterday, and I havent changed anything since then.What more, the bot works fine when I run it on the bot framework emulator on my local ma

python - Callback URL error when setting up webhook for messenger

I'm trying to follow this tutorial to set a chatbot for messenger. I'm stuck on the webhook setup. I added the page token and verify token to heroku, but when I try to add the heroku URL as the callback URL I get The URL couldn't be validated. Callback verification failed with the following error

localization - Vaadin ConfirmDialog changing the title

I want to change the title "Confirm" of a ConfirmDialog to something in my language. I looked at this, but the code does not make sense to me since the show method in my vaadin addon is a static method and it appears to be impossible to show a dialog returned by the factory.I used this code to wrap