PHP code example of dades / scheduledtask

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

    

dades / scheduledtask example snippets


// app/AppKernel.php
public function registerBundles()
{
    // ...
    $bundle = array(
        // ...
        new Dades\ScheduledTaskBundle\DadesScheduledTaskBundle(),
    );
    // ...

    return $bundles;
}

use Dades\ScheduledTaskBundle\Service\ScheduledTaskService;

public function indexAction(Request $request, ScheduledTaskService $scheduled)
{
    //code
}

public function indexAction(Request $request, ScheduledTaskService $scheduledTaskService)
{
    $task = $scheduledTaskService->create();
    $task->setCommand("php --version")->setCronExpresion("* * * * *");
    $scheduledTaskService->save($task);

    return new Response("it works");
}

public function indexAction(Request $request, ScheduledTaskService $scheduledTaskService)
{
    //get the task with id 1
    $task = $scheduledTaskService->getScheduledTask(1);
    //get all tasks
    $tasks = $scheduledTaskService->getScheduledTasks();

    //...
}

public function indexAction(Request $request, ScheduledTaskService $scheduledTaskService)
{
    //get the task with id 1
    $task = $scheduledTaskService->getScheduledTask(1);
    $task->setCommand("crontab -l")->setCronExpresion("0 5 * * *");
    $scheduledTaskService->update($task);

    //...
}

public function indexAction(Request $request, ScheduledTaskService $scheduledTaskService)
{
    //get the task with id 1
    $task = $scheduledTaskService->getScheduledTask(1);
    $scheduledTaskService->delete($task);

    //...
}

if ($this->scheduledTaskService->isDue($task)) {
    exec($task->getCommand(), $stderr, $status);