Repository: spatie/laravel-cronless-schedule
Branch: main
Commit: 1a61e3f724af
Files: 18
Total size: 17.3 KB
Directory structure:
gitextract_i8g8mewl/
├── .editorconfig
├── .gitattributes
├── .github/
│ ├── FUNDING.yml
│ ├── ISSUE_TEMPLATE/
│ │ └── config.yml
│ └── workflows/
│ ├── php-cs-fixer.yml
│ ├── run-tests.yml
│ └── update-changelog.yml
├── .gitignore
├── .php_cs.dist.php
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── composer.json
├── phpunit.xml.dist
├── src/
│ ├── Commands/
│ │ └── ScheduleRunCronlessCommand.php
│ └── CronlessScheduleServiceProvider.php
└── tests/
├── ScheduleRunCronlessCommandTest.php
└── TestCase.php
================================================
FILE CONTENTS
================================================
================================================
FILE: .editorconfig
================================================
; This file is for unifying the coding style for different editors and IDEs.
; More information at https://editorconfig.org
root = true
[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.yml]
indent_size = 2
================================================
FILE: .gitattributes
================================================
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.php.cs export-ignore
/.github export-ignore
================================================
FILE: .github/FUNDING.yml
================================================
github: spatie
custom: https://spatie.be/open-source/support-us
================================================
FILE: .github/ISSUE_TEMPLATE/config.yml
================================================
blank_issues_enabled: true
contact_links:
- name: Feature Request
url: https://github.com/spatie/laravel-cronless-schedule/discussions/new?category=ideas
about: Share ideas for new features
- name: Ask a Question
url: https://github.com/spatie/laravel-cronless-schedule/discussions/new?category=q-a
about: Ask the community for help
================================================
FILE: .github/workflows/php-cs-fixer.yml
================================================
name: Check & fix styling
on: [push]
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs.dist.php --allow-risky=yes
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
================================================
FILE: .github/workflows/run-tests.yml
================================================
name: Tests
on:
- push
- pull_request
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
laravel: ['8.*', '9.*', '10.*', '11.*', '12.*', '13.*']
dependency-version: [prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
- laravel: 8.*
testbench: 6.*
- laravel: 11.*
testbench: 9.*
- laravel: 12.*
testbench: 10.*
- laravel: 13.*
testbench: 11.*
exclude:
- laravel: 10.*
php: 8.0
- laravel: 10.*
php: 7.4
- laravel: 9.*
php: 7.4
- laravel: 11.*
php: 7.4
- laravel: 11.*
php: 8.0
- laravel: 11.*
php: 8.1
- laravel: 12.*
php: 7.4
- laravel: 12.*
php: 8.0
- laravel: 12.*
php: 8.1
- laravel: 13.*
php: '7.4'
- laravel: 13.*
php: '8.0'
- laravel: 13.*
php: '8.1'
- laravel: 13.*
php: '8.2'
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/pest
================================================
FILE: .github/workflows/update-changelog.yml
================================================
name: "Update Changelog"
on:
release:
types: [released]
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: main
- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@v1
with:
latest-version: ${{ github.event.release.name }}
release-notes: ${{ github.event.release.body }}
- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md
================================================
FILE: .gitignore
================================================
build
composer.lock
docs
vendor
coverage
.phpunit.result.cache
.idea
.php-cs-fixer.cache
================================================
FILE: .php_cs.dist.php
================================================
<?php
$finder = Symfony\Component\Finder\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);
return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method' => 'one',
],
],
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'single_trait_insert_per_statement' => true,
])
->setFinder($finder);
================================================
FILE: CHANGELOG.md
================================================
# Changelog
All notable changes to `laravel-cronless-schedule` will be documented in this file
## 1.2.1 - 2025-02-17
### What's Changed
* Laravel 12.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-cronless-schedule/pull/15
**Full Changelog**: https://github.com/spatie/laravel-cronless-schedule/compare/1.2.0...1.2.1
## 1.2.0 - 2024-03-02
### What's Changed
* Convert all tests to Pest by @alexmanase in https://github.com/spatie/laravel-cronless-schedule/pull/13
* Laravel 11.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-cronless-schedule/pull/14
### New Contributors
* @alexmanase made their first contribution in https://github.com/spatie/laravel-cronless-schedule/pull/13
**Full Changelog**: https://github.com/spatie/laravel-cronless-schedule/compare/1.1.1...1.2.0
## 1.1.1 - 2023-01-24
### What's Changed
- Laravel 10.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-cronless-schedule/pull/12
### New Contributors
- @laravel-shift made their first contribution in https://github.com/spatie/laravel-cronless-schedule/pull/12
**Full Changelog**: https://github.com/spatie/laravel-cronless-schedule/compare/1.1.0...1.1.1
## 1.1.0 - 2022-01-19
- support Laravel 9
## 1.0.2 - 2021-01-20
- allow PHP 8
## 1.0.1 - 2020-09-08
- add support for Laravel 8
## 1.0.0 - 2020-06-10
- initial release
================================================
FILE: LICENSE.md
================================================
The MIT License (MIT)
Copyright (c) Spatie bvba <info@spatie.be>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
================================================
FILE: README.md
================================================
# Run the Laravel scheduler without relying on cron
[](https://packagist.org/packages/spatie/laravel-cronless-schedule)

[](https://packagist.org/packages/spatie/laravel-cronless-schedule)
[Laravel's native scheduler](https://laravel.com/docs/master/scheduling) relies on cron to be executed every minute. It's rock solid and in most cases you should stick to using it.
If you want to simulate the scheduler running every minute in a test environment, using cron can be cumbersome. This package provides a command to run the scheduler every minute, without relying on cron. Instead it uses a [ReactPHP](https://reactphp.org) loop.
This is how you can start the cronless schedule:
```bash
php artisan schedule:run-cronless
```
This command will never end. Behind the scenes it will execute `php artisan schedule` every minute.
## Support us
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-cronless-schedule.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-cronless-schedule)
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
## Installation
You can install the package via composer. Probably you only want to use this schedule in a development environment.
```bash
composer require spatie/laravel-cronless-schedule --dev
```
## Usage
This is how you can start the cronless schedule:
```bash
php artisan schedule:run-cronless
```
By default, it will run every minute.
### Manually triggering a run
To perform an extra run of the scheduler, just press enter.
### Using an alternative frequency
If you want to run the scheduler at another frequency, you can pass an amount of seconds to the `frequency` option. Here is an example where the schedule will be run every 5 seconds.
```bash
php artisan schedule:run-cronless --frequency=5
```
### Using another command
If you want to run another command instead of the scheduler, just can pass it to the `command` option. Here is an example where another command will be run every 5 seconds.
```bash
php artisan schedule:run-cronless --command=your-favorite-artisan-command
```
### Only run the schedule for a certain period
By default, the command will run forever. You can shorten that period by passing an amount of seconds to the `stop-after-seconds` option.
In this example we'll stop the command after 5 seconds
```bash
php artisan schedule:run-cronless --stop-after-seconds=5
```
## Testing
``` bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.
## Security
If you've found a bug regarding security please mail [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker.
## Credits
- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
================================================
FILE: composer.json
================================================
{
"name": "spatie/laravel-cronless-schedule",
"description": "Run the Laravel scheduler without relying on cron",
"keywords": [
"spatie",
"laravel-cronless-schedule"
],
"homepage": "https://github.com/spatie/laravel-cronless-schedule",
"license": "MIT",
"authors": [
{
"name": "Freek Van der Herten",
"email": "freek@spatie.be",
"homepage": "https://spatie.be",
"role": "Developer"
}
],
"require": {
"php": "^7.4|^8.0",
"clue/stdio-react": "^2.3",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0|^12.0|^13.0",
"react/event-loop": "^1.1.1"
},
"require-dev": {
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
"pestphp/pest": "^1.22|^2.34|^3.7|^4.4"
},
"autoload": {
"psr-4": {
"Spatie\\CronlessSchedule\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Spatie\\CronlessSchedule\\Tests\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage-html coverage",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"extra": {
"laravel": {
"providers": [
"Spatie\\CronlessSchedule\\CronlessScheduleServiceProvider"
]
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
================================================
FILE: phpunit.xml.dist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Spatie Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
================================================
FILE: src/Commands/ScheduleRunCronlessCommand.php
================================================
<?php
namespace Spatie\CronlessSchedule\Commands;
use Clue\React\Stdio\Stdio;
use Illuminate\Console\Command;
use React\EventLoop\LoopInterface;
class ScheduleRunCronlessCommand extends Command
{
public $signature = 'schedule:run-cronless
{--frequency=60}
{--command=schedule:run}
{--stop-after-seconds=0}
';
public $description = 'Run the scheduler';
protected ?string $command = null;
protected ?int $frequency = null;
protected LoopInterface $loop;
public function __construct(LoopInterface $loop)
{
$this->loop = $loop;
parent::__construct();
}
public function handle()
{
$this->frequency = (int)$this->option('frequency');
$this->command = (string)$this->option('command');
$this
->outputHeader()
->scheduleCommand()
->registerKeypressHandler()
->runCronlessCommand();
$this->loop->run();
}
protected function outputHeader(): self
{
$this->comment("Will execute {$this->command} every {$this->frequency} seconds...");
$this->comment("Press enter to manually invoke a run...");
$this->comment('-------------------------------------------------------');
$this->comment('');
return $this;
}
protected function scheduleCommand(): self
{
$stopAfter = (int)$this->option('stop-after-seconds');
if ($stopAfter > 0) {
$this->loop->addTimer($stopAfter, fn () => $this->loop->stop());
}
$this->loop->addPeriodicTimer($this->frequency, fn () => $this->runCronlessCommand());
return $this;
}
protected function registerKeypressHandler(): self
{
$stdio = new Stdio($this->loop);
$stdio->setEcho(false);
$stdio->on('data', fn () => $this->runCronlessCommand());
return $this;
}
protected function runCronlessCommand()
{
$this->comment($this->timestamp("Running {$this->command}..."));
$this->call($this->command);
$this->comment($this->timestamp("{$this->command} finished."));
$this->comment('');
}
protected function timestamp(string $message): string
{
$currentTime = now()->format('Y-m-d H:i:s');
return "[{$currentTime}] - {$message}";
}
}
================================================
FILE: src/CronlessScheduleServiceProvider.php
================================================
<?php
namespace Spatie\CronlessSchedule;
use Illuminate\Support\ServiceProvider;
use React\EventLoop\Factory;
use React\EventLoop\LoopInterface;
use Spatie\CronlessSchedule\Commands\ScheduleRunCronlessCommand;
class CronlessScheduleServiceProvider extends ServiceProvider
{
public function register()
{
$this->app
->when(ScheduleRunCronlessCommand::class)
->needs(LoopInterface::class)
->give(fn () => Factory::create());
}
public function boot()
{
$this->commands([
ScheduleRunCronlessCommand::class,
]);
}
}
================================================
FILE: tests/ScheduleRunCronlessCommandTest.php
================================================
<?php
uses(Spatie\CronlessSchedule\Tests\TestCase::class);
it('can run the loop without cron')
->artisan('schedule:run-cronless --stop-after-seconds=1')
->assertExitCode(0);
================================================
FILE: tests/TestCase.php
================================================
<?php
namespace Spatie\CronlessSchedule\Tests;
use Orchestra\Testbench\TestCase as Orchestra;
use Spatie\CronlessSchedule\CronlessScheduleServiceProvider;
class TestCase extends Orchestra
{
protected function getPackageProviders($app)
{
return [
CronlessScheduleServiceProvider::class,
];
}
}
gitextract_i8g8mewl/
├── .editorconfig
├── .gitattributes
├── .github/
│ ├── FUNDING.yml
│ ├── ISSUE_TEMPLATE/
│ │ └── config.yml
│ └── workflows/
│ ├── php-cs-fixer.yml
│ ├── run-tests.yml
│ └── update-changelog.yml
├── .gitignore
├── .php_cs.dist.php
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── composer.json
├── phpunit.xml.dist
├── src/
│ ├── Commands/
│ │ └── ScheduleRunCronlessCommand.php
│ └── CronlessScheduleServiceProvider.php
└── tests/
├── ScheduleRunCronlessCommandTest.php
└── TestCase.php
SYMBOL INDEX (13 symbols across 3 files)
FILE: src/Commands/ScheduleRunCronlessCommand.php
class ScheduleRunCronlessCommand (line 9) | class ScheduleRunCronlessCommand extends Command
method __construct (line 25) | public function __construct(LoopInterface $loop)
method handle (line 32) | public function handle()
method outputHeader (line 46) | protected function outputHeader(): self
method scheduleCommand (line 56) | protected function scheduleCommand(): self
method registerKeypressHandler (line 69) | protected function registerKeypressHandler(): self
method runCronlessCommand (line 80) | protected function runCronlessCommand()
method timestamp (line 90) | protected function timestamp(string $message): string
FILE: src/CronlessScheduleServiceProvider.php
class CronlessScheduleServiceProvider (line 10) | class CronlessScheduleServiceProvider extends ServiceProvider
method register (line 12) | public function register()
method boot (line 20) | public function boot()
FILE: tests/TestCase.php
class TestCase (line 8) | class TestCase extends Orchestra
method getPackageProviders (line 10) | protected function getPackageProviders($app)
Condensed preview — 18 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (19K chars).
[
{
"path": ".editorconfig",
"chars": 338,
"preview": "; This file is for unifying the coding style for different editors and IDEs.\n; More information at https://editorconfig."
},
{
"path": ".gitattributes",
"chars": 430,
"preview": "# Path-based git attributes\n# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html\n\n# Ignore all test and"
},
{
"path": ".github/FUNDING.yml",
"chars": 64,
"preview": "github: spatie\ncustom: https://spatie.be/open-source/support-us\n"
},
{
"path": ".github/ISSUE_TEMPLATE/config.yml",
"chars": 365,
"preview": "blank_issues_enabled: true\ncontact_links:\n - name: Feature Request\n url: https://github.com/spatie/laravel-cronl"
},
{
"path": ".github/workflows/php-cs-fixer.yml",
"chars": 506,
"preview": "name: Check & fix styling\n\non: [push]\n\njobs:\n php-cs-fixer:\n runs-on: ubuntu-latest\n\n steps:\n - name: Checko"
},
{
"path": ".github/workflows/run-tests.yml",
"chars": 2115,
"preview": "name: Tests\n\non:\n - push\n - pull_request\n\njobs:\n test:\n runs-on: ${{ matrix.os }}\n\n strategy:\n fail-fast: "
},
{
"path": ".github/workflows/update-changelog.yml",
"chars": 645,
"preview": "name: \"Update Changelog\"\n\non:\n release:\n types: [released]\n\njobs:\n update:\n runs-on: ubuntu-latest\n\n steps:\n "
},
{
"path": ".gitignore",
"chars": 91,
"preview": "build\ncomposer.lock\ndocs\nvendor\ncoverage\n.phpunit.result.cache\n.idea\n.php-cs-fixer.cache\n\n\n"
},
{
"path": ".php_cs.dist.php",
"chars": 1282,
"preview": "<?php\n\n$finder = Symfony\\Component\\Finder\\Finder::create()\n ->in([\n __DIR__ . '/src',\n __DIR__ . '/test"
},
{
"path": "CHANGELOG.md",
"chars": 1388,
"preview": "# Changelog\n\nAll notable changes to `laravel-cronless-schedule` will be documented in this file\n\n## 1.2.1 - 2025-02-17\n\n"
},
{
"path": "LICENSE.md",
"chars": 1090,
"preview": "The MIT License (MIT)\n\nCopyright (c) Spatie bvba <info@spatie.be>\n\nPermission is hereby granted, free of charge, to any "
},
{
"path": "README.md",
"chars": 3796,
"preview": "# Run the Laravel scheduler without relying on cron\n\n[;\n\nit('can run the loop without cron')\n ->artisan('schedule"
},
{
"path": "tests/TestCase.php",
"chars": 336,
"preview": "<?php\n\nnamespace Spatie\\CronlessSchedule\\Tests;\n\nuse Orchestra\\Testbench\\TestCase as Orchestra;\nuse Spatie\\CronlessSched"
}
]
About this extraction
This page contains the full source code of the spatie/laravel-cronless-schedule GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 18 files (17.3 KB), approximately 5.1k tokens, and a symbol index with 13 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.