PHP code example of nixphp / schedule

1. Go to this page and download the library: Download nixphp/schedule 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/ */

    

nixphp / schedule example snippets


use NixPHP\Schedule\Core\ScheduledJobInterface;
use NixPHP\Queue\QueueJobInterface;

class CleanupTempFiles implements ScheduledJobInterface, QueueJobInterface
{
    public function getCronExpression(): string
    {
        return '0 * * * *'; // every hour
    }

    public function execute(): void
    {
        // cleanup logic
    }
}

$scheduler->addScheduledJob(CleanupTempFiles::class);

$scheduler->addScheduledJob(CleanupTempFiles::class, [
    'path' => '/tmp'
]);

// app/config.php
return [
    'queue' => [
        // If true (default): only the latest scheduled job is kept
        // If false: every scheduled run is queued and processed
        'coalesce' => true,
    ],
];