Skip to content

Instantly share code, notes, and snippets.

View vishwarajanand's full-sized avatar
😎
¯\_(ツ)_/¯

Vishwaraj Anand vishwarajanand

😎
¯\_(ツ)_/¯
View GitHub Profile
@vishwarajanand
vishwarajanand / crcTest.php
Created August 10, 2023 13:53
Product CRC32C in Pure PHP7.4+
<?php
use Google\CRC32\CRC32;
use GuzzleHttp\Psr7\Utils;
include __DIR__.'/vendor/autoload.php';
$filePath = __DIR__.'/tests/System/data/5mb.txt';
## USAGE:
# Paste the file into https://github.com/googleapis/google-cloud-php/tree/main/Storage
@vishwarajanand
vishwarajanand / deleteUnusedTopics.php
Created December 14, 2023 13:44
Delete topics with a certain prefix name from Google PubSub
<?php
require_once __DIR__ . '/../vendor/autoload.php';
## Delete all topics and subscriptions with name having prefix: `gcloud_testing_`
use Google\Cloud\PubSub\PubSubClient;
$client = new PubSubClient();
$topics = $client->topics();
@vishwarajanand
vishwarajanand / deleteUnusedBuckets.php
Created December 14, 2023 13:50
Delete buckets (and all objects inside it) with a certain prefix name from Google Cloud Storage
<?php
require_once __DIR__ . '/../vendor/autoload.php';
## Delete all buckets (and objects inside it) with bucket name having prefix: `gcloud_testing_`
use Google\Cloud\Storage\StorageClient;
$client = new StorageClient();
$buckets = $client->buckets();
@vishwarajanand
vishwarajanand / issue_7088.php
Created February 26, 2024 22:38
Testing Google Cloud Storage Resumable Uploader headers
<?php
// Ref: https://github.com/googleapis/google-cloud-php/issues/7088
require __DIR__ . "/vendor/autoload.php";
use Google\Cloud\Storage\StorageClient;
$gcsClient = new StorageClient([
"projectId" => "XXXXXXX",
"requestTimeout" => 10,
]);
$gcsBucket = $gcsClient->bucket("XXXXXXX");
@vishwarajanand
vishwarajanand / folder_upload_resumable.php
Last active March 15, 2024 11:38
Folder uploads for google cloud php storage
<?php
require __DIR__ . "/vendor/autoload.php";
use Google\Cloud\Storage\StorageClient;
use GuzzleHttp\Promise\Each;
// Create a Storage client
$storage = new StorageClient([
'projectId' => 'XXXXXXXXXX',
@vishwarajanand
vishwarajanand / 5118-touch_throws_warnings.php
Created March 14, 2024 12:25
Test Script for implementing touch in google cloud storage php library
<?php
require __DIR__ . '/vendor/autoload.php';
// https://github.com/googleapis/google-cloud-php/issues/5118
// Warning: touch(): Google\Cloud\Storage\StreamWrapper::stream_metadata is not implemented! #5118
// PR raised: https://github.com/googleapis/google-cloud-php/pull/7144
use Google\Cloud\Storage\StorageClient;
$client = new StorageClient(['projectId' => 'XXXXXXXXXXX']);
@vishwarajanand
vishwarajanand / testParallelUploadToGcs.php
Created March 15, 2024 13:31
Uploading GCS Objects in parallel using PHP SDK
<?php
require __DIR__ . "/vendor/autoload.php";
use Google\Cloud\Storage\StorageClient;
use GuzzleHttp\Promise;
# control the number of objects to upload
$NUM_OBJECTS = 5;
$storage = new StorageClient();
import { Storage } from './build/esm/src/storage.js';
// Path: nodejs-storage/issue_2389.js
const storage = new Storage();
const myBucket = storage.bucket('thebookclub');
const file = myBucket.file('sample.txt');
file.copy('new_sample.txt', {
contentType: 'outer', // A property from CopyOptions
metadata: {
// Typed as FileMetadata