PHPackages                             litvinab/cron-event - 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. litvinab/cron-event

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

litvinab/cron-event
===================

Current symfony2 bundle generates events inside the application based on timers stored in DB.

v1.0(9y ago)1490PHPPHP &gt;=5.5

Since Sep 22Pushed 9y ago1 watchersCompare

[ Source](https://github.com/litvinab/cron-event)[ Packagist](https://packagist.org/packages/litvinab/cron-event)[ Docs](https://github.com/litvinab/cron-event)[ RSS](/packages/litvinab-cron-event/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

cron-event
==========

[](#cron-event)

Symfony2 bundle to set and run cron-based timers and events. It generates events inside the application based on timers stored in DB.

Currently bundle supports MongoDB only.

Steps to install and check
--------------------------

[](#steps-to-install-and-check)

1. run command in project root folder: `composer require litvinab/cron-event`
2. add `new Litvinab\Bundle\CronEventBundle\CronEventBundle()` in `AppKernel.php`
3. setup cron task: `php app/console cron:run` for each minute
4. for testing purposes add bundle test routes to `routing.yml`:

```
cron:
    resource: "@CronEventBundle/Resources/config/routing.yml"
    prefix:   /cron
```

5. To add test timer (1 minute timer) and event go to `http://your-domain/cron/`
6. Added schedules will be displayed on this page: `http://your-domain/cron/show``status` fields should be `unexpired`
7. Refresh `http://your-domain/cron/show` page after 1-2 minutes after point #5. `status` fields should be `expired` it means that bundle works right.

!! Do not forget to remove test routes from `routing.yml`. It's not secure to leave it there.

Supported event types
---------------------

[](#supported-event-types)

`timer` - event in application will be triggered after N milliseconds.

`event` - event in application will be triggered in specified date and time.

How to use
----------

[](#how-to-use)

### 1. Set event in your code

[](#1-set-event-in-your-code)

In controller:

```
// get cron manager
$cronManager = $this->get('cron_event.manager');

// set timer with: human name, name, period
// name of the symfony event: `cron_event.` + name
$timer = $cronManager->setTimer('My timer', 'test_timer', 60);
```

### 2. Add cron event subscriber

[](#2-add-cron-event-subscriber)

Of course you are able to create event listeners if you wish.

services.yml:

```
services:
     app.subscriber.cron:
          class: AppBundle\EventSubscriber\CronSubscriber
          calls:
            - [setLogger, [@cron_event.logger]]
          tags:
            - { name: kernel.event_subscriber }
```

/YourBundle/EventSubscriber/CronSubscriber.php:

```
