google cloud platform – PHP GCP StorageClient get list of directories ( prefixes )?

I am trying to get list of all available ( directories ) which called prefix inside GCP storage API , I’ve read all examples code which available on this link by Google dev .

unfortunately i am still unable to list only directories , since the bucket has over 800k directory each dir is for a specific user.

also , when i query the objects its taking too long since the bucket has millions of records , is it possible to make it paginated query since there is nextPageToken ?

here is what i am trying so far :

try {
                $bucket = $this->storage->bucket('xx.xx.xx');
                $options = ['prefix' => null,   'fields' => '*,nextPageToken'];
                foreach ($bucket->objects($options) as $object) {
                
                $object = $bucket->object($object->name());
                $info = $object->info();
                echo "<pre>" ;print_r($info);
                
        } catch (Exception $e) {
            // maybe invalid private key ?
            print_r($e);
        }

Read more here: Source link