PHP code example of google / cloud-tasks
1. Go to this page and download the library: Download google/cloud-tasks library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
google / cloud-tasks example snippets
use Google\Cloud\Tasks\V2\CloudTasksClient;
use Google\Cloud\Tasks\V2\Queue;
$client = new CloudTasksClient();
$project = 'example-project';
$location = 'us-central1';
$queue = uniqid('example-queue-');
$queueName = $client::queueName($project, $location, $queue);
// Create a queue
$locationName = $client::locationName($project, $location);
$queue = new Queue([
'name' => $queueName
]);
$queue->setName($queueName);
$client->createQueue($locationName, $queue);
echo "$queueName created." . PHP_EOL;
// List queues
echo 'Listing the queues' . PHP_EOL;
$resp = $client->listQueues($locationName);
foreach ($resp->iterateAllElements() as $q) {
echo $q->getName() . PHP_EOL;
}
// Delete the queue
$client->deleteQueue($queueName);