Skip to content

Instantly share code, notes, and snippets.

@saranshdhingra
Created February 15, 2022 14:02
Show Gist options
  • Save saranshdhingra/5e53365371d265fd28fc9b15534289b4 to your computer and use it in GitHub Desktop.
Save saranshdhingra/5e53365371d265fd28fc9b15534289b4 to your computer and use it in GitHub Desktop.
{
"require": {
"google/cloud-firestore": "^1.21"
}
}
FROM ubuntu:18.04
WORKDIR /var/www
RUN apt-get update
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC
RUN apt-get install -y php7.2-dev php-pear libz-dev curl zip
RUN pecl install grpc
RUN echo "extension=grpc.so" > /etc/php/7.2/cli/conf.d/grpc.ini
COPY . .
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer update
# comment this if you intend to supply credentials directly in the PHP file
ENV GOOGLE_APPLICATION_CREDENTIALS=/var/www/key.json
CMD ["tail","-f"]
{
"0":"overwrite this file with your service account key contents"
}
<?php
require 'vendor/autoload.php';
use Google\Cloud\Firestore\FirestoreClient;
// the projectId will either be fetched from the GOOGLE_APPLICATION_CREDENTIALS env supplied in Dockerfile
// or you can specify here and comment it in the Dockerfile
$db = new FirestoreClient();
// change the collectionName here
$usersRef = $db->collection('issue-3847');
$snapshot = $usersRef->documents();
foreach ($snapshot as $user) {
printf('User: %s' . PHP_EOL, $user->id());
printf(PHP_EOL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment