PHPackages                             denniskrol/nativephp-background-tasks - 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. denniskrol/nativephp-background-tasks

ActiveNativephp-plugin

denniskrol/nativephp-background-tasks
=====================================

Background task scheduling plugin for NativePHP Mobile — wraps Laravel's scheduler and runs tasks via WorkManager (Android) and BGTaskScheduler (iOS).

v1.1.0(today)02↑2900%MITKotlinPHP ^8.4

Since Aug 25Pushed todayCompare

[ Source](https://github.com/denniskrol/nativephp-background-tasks)[ Packagist](https://packagist.org/packages/denniskrol/nativephp-background-tasks)[ RSS](/packages/denniskrol-nativephp-background-tasks/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (3)Used By (0)

NativePHP Background Tasks
==========================

[](#nativephp-background-tasks)

[![Latest Version](https://camo.githubusercontent.com/00502b496208103a86f1b4afbc9fbd7212a52684fdfeb51a3235146c31929117/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64656e6e69736b726f6c2f6e61746976657068702d6261636b67726f756e642d7461736b732e737667)](https://packagist.org/packages/denniskrol/nativephp-background-tasks)[![Total Downloads](https://camo.githubusercontent.com/8c45c0480219522db8ed7a77f0479843736e78cc84637da597e70d310afd4e6a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64656e6e69736b726f6c2f6e61746976657068702d6261636b67726f756e642d7461736b732e737667)](https://packagist.org/packages/denniskrol/nativephp-background-tasks)[![License](https://camo.githubusercontent.com/2ec7b5ee6c0473efe92f064273bcd2e29fadcf75d5a624fe4a4475ada057f4b2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f64656e6e69736b726f6c2f6e61746976657068702d6261636b67726f756e642d7461736b732e737667)](https://packagist.org/packages/denniskrol/nativephp-background-tasks)

Background task scheduling plugin for [NativePHP Mobile](https://nativephp.com). Lets you define recurring jobs with Laravel's standard scheduler and run them via Android **WorkManager** and iOS **BGTaskScheduler** — even when the app is backgrounded or killed.

> Android is fully implemented for NativePHP Mobile `^4.2`. The iOS handler remains a stub.

Requirements
------------

[](#requirements)

- PHP `^8.4`
- Laravel `^11.0` or `^12.0` / `^13.0`
- `nativephp/mobile ^4.2`
- Android: `min_version 33` (uses `androidx.work:work-runtime-ktx`)
- iOS: `min_version 16.0`

Installation
------------

[](#installation)

```
composer require denniskrol/nativephp-background-tasks
```

Enable the package in your app's `NativeServiceProvider::plugins()` list, then rebuild the mobile app:

```
php artisan native:run android
# or
php artisan native:run ios
```

Defining tasks
--------------

[](#defining-tasks)

Use Laravel's normal scheduler in `routes/console.php`. The plugin adds a set of mobile-aware constraint methods you can chain on:

```
use Illuminate\Support\Facades\Schedule;

Schedule::command('sync:data')
    ->everyFifteenMinutes()
    ->onAnyNetwork();

Schedule::command('cache:warm')
    ->hourly()
    ->onWifi()
    ->whileCharging();

Schedule::command('export:reports')
    ->daily()
    ->onWifi()
    ->whileCharging()
    ->whenIdle()
    ->longRunning();
```

Tasks are registered automatically when the NativePHP app runtime starts. You can also register them manually from code running in the mobile app:

```
use Denniskrol\NativePHPBackgroundTasks\Facades\BackgroundTasks;

BackgroundTasks::register();
```

This walks the schedule, serialises each periodic event into a task descriptor, and calls the `BackgroundTasks.Register` bridge function. The package automatically does this on each normal app start, adding, updating, and removing Android work as the schedule changes. It deliberately skips the ephemeral PHP runtime used to execute a background task.

Constraint methods
------------------

[](#constraint-methods)

MethodAndroidiOS`onAnyNetwork()``NetworkType.CONNECTED``requiresNetworkConnectivity = true``onWifi()``NetworkType.UNMETERED``requiresNetworkConnectivity = true``whileCharging()``setRequiresCharging(true)``requiresExternalPower = true``whenBatteryNotLow()``setRequiresBatteryNotLow(true)`*Ignored*`whenStorageNotLow()``setRequiresStorageNotLow(true)`*Ignored*`whenIdle()``setRequiresDeviceIdle(true)`Promotes to `BGProcessingTask``longRunning()`*No-op*Promotes to `BGProcessingTask`Supported intervals
-------------------

[](#supported-intervals)

`everyFifteenMinutes()`, `everyTwentyMinutes()`, `everyThirtyMinutes()`, `hourly()`, `everyTwoHours()`, `everyThreeHours()`, `everyFourHours()`, `everySixHours()`, `daily()`.

Other Laravel scheduler frequencies are ignored by the collector — both Android WorkManager and iOS BGTaskScheduler enforce minimum periodic intervals (15 minutes on Android, ~15 minutes practical floor on iOS).

PHP API
-------

[](#php-api)

```
use Denniskrol\NativePHPBackgroundTasks\Facades\BackgroundTasks;

// Push the current schedule to the OS scheduler
BackgroundTasks::register();

// Trigger registered tasks immediately (testing only — bypasses constraints)
BackgroundTasks::runNow();

// Cancel a single task
BackgroundTasks::cancel('com.denniskrol.nativephp.task.sync_data');

// Inspect what's scheduled
$registered = BackgroundTasks::getRegistered();

// Or just see the descriptors the collector would push
$tasks = BackgroundTasks::tasks();
```

JavaScript API
--------------

[](#javascript-api)

```
await window.NativePHP.BackgroundTasks.Register({ tasks: [...] });
await window.NativePHP.BackgroundTasks.RunNow();
await window.NativePHP.BackgroundTasks.Cancel({ taskId: 'com.denniskrol.nativephp.task.sync_data' });
const { tasks } = await window.NativePHP.BackgroundTasks.GetRegistered();
```

Bridge methods
--------------

[](#bridge-methods)

MethodParamsReturns`BackgroundTasks.Register``{ tasks: TaskDescriptor[] }``{ success, registered }``BackgroundTasks.RunNow`—`{ success, message }``BackgroundTasks.Cancel``{ taskId }``{ success, taskId }``BackgroundTasks.GetRegistered`—`{ success, tasks[] }``TaskDescriptor` shape:

```
{
    id: 'com.denniskrol.nativephp.task.sync_data',
    command: 'sync:data',
    intervalMinutes: 15,
    constraints: {
        network: 'any' | 'wifi' | null,
        charging: boolean,
        batteryNotLow: boolean,
        storageNotLow: boolean,
        idle: boolean,
        longRunning: boolean
    }
}
```

Native integration
------------------

[](#native-integration)

### Android

[](#android)

This package declares `androidx.work:work-runtime-ktx:2.9.1`. The `Register` bridge function enqueues a `PeriodicWorkRequest` per task with the right `Constraints`. When WorkManager runs a task, the package worker initializes NativePHP's background environment, boots an ephemeral PHP runtime, executes the bundled artisan command, and shuts the runtime down. No host-app Kotlin code is required.

`RunNow` enqueues one unconstrained one-time execution per registered task. Registered task descriptors are persisted in app-private storage, so `GetRegistered` and `RunNow` remain available after a cold start.

### iOS

[](#ios)

`BGTaskScheduler` requires every task identifier to be listed in `Info.plist > BGTaskSchedulerPermittedIdentifiers`. The plugin declares the `com.denniskrol.nativephp.task.*` prefix; iOS will reject any identifier outside that prefix.

You must register a handler in your `AppDelegate` (or SwiftUI App) for each identifier you submit:

```
BGTaskScheduler.shared.register(forTaskWithIdentifier: "com.denniskrol.nativephp.task.sync_data", using: nil) { task in
    // run the sync:data artisan command, then call task.setTaskCompleted(success: ...)
}
```

The plugin's `Register` bridge submits the request; your handler runs the actual work.

Testing
-------

[](#testing)

**Android (ADB):**

```
adb shell cmd jobscheduler run -f
```

**iOS (Xcode LLDB):**

```
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.denniskrol.nativephp.task.sync_data"]

```

Or just call `BackgroundTasks::runNow()` from PHP — it bypasses constraints and is intended for development only.

License
-------

[](#license)

MIT

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance100

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

0d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10570858?v=4)[denniskrol](/maintainers/denniskrol)[@denniskrol](https://github.com/denniskrol)

---

Top Contributors

[![denniskrol](https://avatars.githubusercontent.com/u/10570858?v=4)](https://github.com/denniskrol "denniskrol (4 commits)")[![jomarmata24](https://avatars.githubusercontent.com/u/64277739?v=4)](https://github.com/jomarmata24 "jomarmata24 (1 commits)")

### Embed Badge

![Health badge](/badges/denniskrol-nativephp-background-tasks/health.svg)

```
[![Health](https://phpackages.com/badges/denniskrol-nativephp-background-tasks/health.svg)](https://phpackages.com/packages/denniskrol-nativephp-background-tasks)
```

###  Alternatives

[laravel/sail

Docker files for running a basic Laravel application.

1.9k212.4M1.5k](/packages/laravel-sail)[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M341](/packages/laravel-ai)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

80427.1M249](/packages/laravel-mcp)[tallstackui/tallstackui

TallStackUI is a powerful suite of Blade components that elevate your workflow of Livewire applications.

731189.9k16](/packages/tallstackui-tallstackui)[propaganistas/laravel-disposable-email

Disposable email validator

6023.2M7](/packages/propaganistas-laravel-disposable-email)[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k161.4k2](/packages/mike-bronner-laravel-model-caching)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
