https://github.com/schema31/php-couchdb-watcher
A simple PHP watcher to attach callbacks to CouchDB documents changes.
https://github.com/schema31/php-couchdb-watcher
couchdb php7
Last synced: 5 months ago
JSON representation
A simple PHP watcher to attach callbacks to CouchDB documents changes.
- Host: GitHub
- URL: https://github.com/schema31/php-couchdb-watcher
- Owner: Schema31
- Created: 2020-04-27T10:53:18.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-28T12:48:37.000Z (about 6 years ago)
- Last Synced: 2025-10-04T00:57:42.251Z (9 months ago)
- Topics: couchdb, php7
- Language: PHP
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# php-couchdb-watcher
This package provides a simple watcher to attach callbacks to CouchDB documents changes.
### Installation
The recommended installation method is by using [composer](https://getcomposer.org/)
composer require schema31/php-couchdb-watcher
### Usage
Three steps are required in order to use the watcher.
Create it passing a key to save last change processed, CouchDB url and options.
```php
'now', // taken into account only if store is empty, default is '0'
'store' => new Schema31\CouchDBWatcher\Store\FileStore() // FileStore is the default one. You can provide your own object, that implements the StoreInterface
];
$watcher = new Watcher('main_db', 'https://couch.com/db', $options);
```
Then attach all the callbacks you want.
```php
addCallback(function($change) {
echo $change->id.PHP_EOL;
});
```
And just run it.
```php
run();
```
### Error handling
If any of the defined callbacks produces an error program will exit, so you can fix it and then launch again.
The last change processed is saved in the store only if all the callbacks are executed without errors.