This repository provides an example PHP application showcasing the usage of MongoDB TTL indexes and change streams. It includes a command-line script to listen for changes in MongoDB collections with TTL indexes, handling insert, update, replace, and delete events.
- Demonstrates setting up TTL indexes for automatic document expiration.
- Illustrates using change streams to monitor collection changes in real-time.
- Handles various CRUD operations and tracks document changes efficiently.
- PHP >= 8.2
- MongoDB PHP Driver
- MongoDB server with replica set configured (for change streams)
- Docker
-
Clone and navigate to the project directory:
git clone https://github.com/your-username/php-mongo-ttl-index-change-stream-listener-example.git cd php-mongo-ttl-index-change-stream-listener-example
-
Start the project via make file setup command:
make setup
This command will install the project dependencies and set up the database via Docker.
Run the listener command to start monitoring MongoDB collection changes:
php bin/console dev:mongo-stream-listener
Now all changes in the records
collection will be displayed in the console output.
Use make command to see all available commands:
> make
Usage: make [command]
Commands available:
check-docker Check if Docker is installed
ci Run the CI pipeline
database-cleanup Cleanup the database
database-migrate Migrate the database
database-seed Create a new record in the database
help Show this help message
install-dependencies Install the project dependencies
mongo-stream-listener Start the MongoDB stream listener
playground Start a PHP playground dockerized environment
setup Setup the project
setup-database Setup the database
test Run the tests
This project is licensed under the MIT License - see the LICENSE file for details.