Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products. If you have feedback or questions as you navigate the site, click Send Feedback.

As PHP version 5.5 is no longer supported by the community, we strongly recommend new apps use the PHP 7+ runtime.

A PHP Task Queue Example

The following code creates a task that will be sent as a POST request to the /worker handler of the application. The task contains name and action data, and will be processed by the default queue:

$task = new PushTask(
    ['name' => 'john doe', 'action' => 'send_reminder']);
$task_name = $task->add();

You can also add tasks in bulk to a queue using PushQueue. In the following example, two PushTask objects are added to a PushQueue using the addTasks() method.

$task1 = new PushTask('/someUrl');
$task2 = new PushTask('/someOtherUrl');
$queue = new PushQueue();
$queue->addTasks([$task1, $task2]);

When you use PushTask and PushQueue, include these statements at the top of your PHP file:

use google\appengine\api\taskqueue\PushTask;
use google\appengine\api\taskqueue\PushQueue;