PHP code example of google / cloud-scheduler

1. Go to this page and download the library: Download google/cloud-scheduler 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-scheduler example snippets




use Google\Cloud\Scheduler\V1\AppEngineHttpTarget;
use Google\Cloud\Scheduler\V1\CloudSchedulerClient;
use Google\Cloud\Scheduler\V1\Job;
use Google\Cloud\Scheduler\V1\Job\State;

$client = new CloudSchedulerClient();
$projectId = '[MY_PROJECT_ID]';
$location = 'us-central1';
$parent = CloudSchedulerClient::locationName($projectId, $location);
$job = new Job([
    'name' => CloudSchedulerClient::jobName(
        $projectId,
        $location,
        uniqid()
    ),
    'app_engine_http_target' => new AppEngineHttpTarget([
        'relative_uri' => '/'
    ]),
    'schedule' => '* * * * *'
]);
$client->createJob($parent, $job);

foreach ($client->listJobs($parent) as $job) {
    printf(
        'Job: %s : %s' . PHP_EOL,
        $job->getName(),
        State::name($job->getState())
    );
}