PHPackages                             stackkit/laravel-google-cloud-scheduler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. stackkit/laravel-google-cloud-scheduler

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

stackkit/laravel-google-cloud-scheduler
=======================================

v5.0.0(3mo ago)33266.0k↓41%6MITPHPCI passing

Since Jun 26Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/stackkit/laravel-google-cloud-scheduler)[ Packagist](https://packagist.org/packages/stackkit/laravel-google-cloud-scheduler)[ GitHub Sponsors](https://github.com/marickvantuil)[ RSS](/packages/stackkit-laravel-google-cloud-scheduler/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (16)Versions (32)Used By (0)

[![](/logo.png)](/logo.png)

[![Run tests](https://github.com/stackkit/laravel-google-cloud-scheduler/actions/workflows/run-tests.yml/badge.svg)](https://github.com/stackkit/laravel-google-cloud-scheduler/actions/workflows/run-tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/55875de16a28cea4ed3600d18e06b17a215d8a77f4669afd3889de10f9128868/68747470733a2f2f706f7365722e707567782e6f72672f737461636b6b69742f6c61726176656c2d676f6f676c652d636c6f75642d7363686564756c65722f762f737461626c652e737667)](https://packagist.org/packages/stackkit/laravel-google-cloud-scheduler)[![Downloads](https://camo.githubusercontent.com/b27f8dc4e1bdd5d41f5a6341d0e508ec5cd1b9c77c202e28970895ff71d29cf1/68747470733a2f2f706f7365722e707567782e6f72672f737461636b6b69742f6c61726176656c2d676f6f676c652d636c6f75642d7363686564756c65722f646f776e6c6f6164732e737667)](https://packagist.org/packages/stackkit/laravel-database-emails)

Companion packages: [Cloud Tasks](https://github.com/stackkit/laravel-google-cloud-tasks-queue), [Cloud Logging](https://github.com/marickvantuil/laravel-google-cloud-logging)

Introduction
============

[](#introduction)

This package allows you to use Google Cloud Scheduler to schedule Laravel commands.

How it works
============

[](#how-it-works)

Cloud Scheduler will make HTTP calls to your application. This package adds an endpoint to your application that accepts these HTTP calls with their payload (an Artisan command) and execute them.

There are two ways to schedule commands using this package:

1. Schedule the `schedule:run` commandThis is the easiest way to use this package. You can schedule the `schedule:run` command to run every minute.

2. Schedule commands separatelyIf your application does not have commands that should run every minute, you may choose to schedule them individually.

If the command uses `withoutOverlapping`, `before`, `after`, `onSuccess`, `thenPing`, etc, this package will respect those settings, as long as the command is also scheduled in the console kernel.

For example, let's say we have to generate a report every day at 3:00 AM. We can schedule the `reports:generate` command to run at 3:00 AM using Cloud Scheduler. After the report is generated, OhDear should be pinged.

Firstly, schedule the command in Cloud Tasks:

[![](/schedule-command-example.png)](/schedule-command-example.png)Then, schedule the command in the console kernel:

```
public function schedule(Schedule $schedule)
{
    $schedule->command('report:generate')
        ->thenPing('https://ohdear.app/ping');
}
```

The package will pick up on the scheduled settings and ping OhDear after the command has run.

Requirements
============

[](#requirements)

This package requires Laravel 12 or 13.

Installation
============

[](#installation)

1 - Require the package using Composer

```
composer require stackkit/laravel-google-cloud-scheduler
```

2 - Define environment variables

`CLOUD_SCHEDULER_APP_URL` - This should be the URL defined in the `URL` field of your Cloud Scheduler job.

`CLOUD_SCHEDULER_SERVICE_ACCOUNT` - The e-mail address of the service account invocating the task.

Optionally, you may publish the configuration file:

```
php artisan vendor:publish --tag=cloud-scheduler-config
```

3 - Ensure PHP executable is in open\_basedir. This is required for the package to run Artisan commands.

How to find the executable:

```
php artisan tinker --execute="(new Symfony\\Component\\Process\\PhpExecutableFinder())->find()"
```

4 - Optional, but highly recommended: server configuration

Since Artisan commands are now invoked via an HTTP request, you might encounter issues with timeouts. Here's how to adjust them:

```
server {
    # other server configuration ...

    location /cloud-scheduler-job {
        proxy_connect_timeout 600s;
        proxy_read_timeout 600s;
        fastcgi_read_timeout 600s;
    }

    # other locations and server configuration ...
}
```

5 - Optional, but highly recommended: set application `RUNNING_IN_CONSOLE`

Some Laravel service providers only register their commands if the application is being accessed through the command line (Artisan). Because we are calling Laravel scheduler from a HTTP call, that means some commands may never register, such as the Laravel Scout command:

```
/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    if ($this->app->runningInConsole()) {
        $this->commands([
            FlushCommand::class,
            ImportCommand::class,
            IndexCommand::class,
            DeleteIndexCommand::class,
        ]);

        $this->publishes([
            __DIR__.'/../config/scout.php' => $this->app['path.config'].DIRECTORY_SEPARATOR.'scout.php',
        ]);
    }
}
```

To circumvent this, please add the following to `bootstrap/app.php`

```
