Al code in the snippets directory demonstrate how to invoke Cloud Tasks from PHP.
src/create_http_task.php
is a simple function to create tasks with an HTTP target.
-
Enable APIs - Enable the Cloud Tasks API and create a new project or select an existing project.
-
Download The Credentials - Click "Go to credentials" after enabling the APIs. Click "New Credentials" and select "Service Account Key". Create a new service account, use the JSON key type, and select "Create". Once downloaded, set the environment variable
GOOGLE_APPLICATION_CREDENTIALS
to the path of the JSON key that was downloaded. -
Clone the repo and cd into this directory
$ git clone https://github.com/GoogleCloudPlatform/php-docs-samples $ cd php-docs-samples/tasks
-
Install dependencies via Composer. Run
php composer.phar install
(if composer is installed locally) orcomposer install
(if composer is installed globally). -
Create a Queue To create a queue using the Cloud SDK, use the following gcloud command:
gcloud tasks queues create <QUEUE_NAME>
-
Run
php src/create_http_task.php
. The usage will print for each if no arguments are provided:$> php src/create_http_task.php Usage: php src/create_http_task.php PROJECT_ID LOCATION_ID QUEUE_ID URL [PAYLOAD]
where:
PROJECT_ID
is your Google Cloud Project id.QUEUE_ID
is your queue id. Queue IDs already created can be listed withgcloud tasks queues list
.LOCATION_ID
is the location of your queue.
Determine the location ID, which can be discovered withgcloud tasks queues describe <QUEUE_NAME>
, with the location embedded in the "name" value (for instance, if the name is "projects/my-project/locations/us-central1/queues/my-queue", then the location is "us-central1").URL
is the full URL to your target endpoint.
- See CONTRIBUTING.md
- See LICENSE