Download the PHP package sqrtspace/spacetime without Composer
On this page you can find all versions of the php package sqrtspace/spacetime. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sqrtspace/spacetime
More information about sqrtspace/spacetime
Files in sqrtspace/spacetime
Package spacetime
Short Description High-performance PHP library for memory-efficient processing of large datasets with streaming, batching, and time/space complexity optimization
License Apache-2.0
Homepage https://github.com/sqrtspace/spacetime-php
Informations about the package spacetime
SqrtSpace SpaceTime for PHP
Memory-efficient algorithms and data structures for PHP using Williams' √n space-time tradeoffs.
Paper Repository: github.com/sqrtspace/sqrtspace-paper
Installation
Core Concepts
SpaceTime implements theoretical computer science results showing that many algorithms can achieve better memory usage by accepting slightly slower runtime. The key insight is using √n memory instead of n memory, where n is the input size.
Key Features
- External Sorting: Sort large datasets that don't fit in memory
- External Grouping: Group and aggregate data with minimal memory usage
- Streaming Operations: Process files and data streams efficiently
- Memory Pressure Handling: Automatic response to low memory conditions
- Checkpoint/Resume: Save progress and resume long-running operations
- Laravel Integration: Deep integration with Laravel collections and queries
Quick Start
Examples
Basic Examples
See examples/comprehensive_example.php
for a complete demonstration of all features including:
- Memory-efficient arrays and dictionaries
- External sorting and grouping
- Stream processing
- CSV import/export
- Batch processing with checkpoints
- Memory pressure monitoring
Laravel Application
Check out examples/laravel-app/
for a complete Laravel application demonstrating:
- Streaming API endpoints
- Memory-efficient CSV exports
- Background job processing with checkpoints
- Real-time analytics with SSE
- Production-ready configurations
See the Laravel example README for setup instructions and detailed usage.
Features
1. Memory-Efficient Collections
2. External Algorithms
3. Streaming Operations
4. Database Integration
5. Laravel Integration
6. Memory Pressure Handling
7. Checkpointing for Fault Tolerance
Real-World Examples
Processing Large CSV Files
Large Data Export
Batch Processing with Memory Limits
Configuration
Advanced Usage
JSON Lines Processing
Streaming Operations
Custom Batch Jobs
Testing
Performance Considerations
-
Chunk Size: The default √n chunk size is optimal for most cases, but you can tune it:
-
Compression: Enable for text-heavy data, disable for already compressed data:
- Storage Location: Use fast local SSDs for external storage:
Framework Integration
Laravel
Symfony
For a complete Symfony integration example, see our Symfony bundle documentation.
Troubleshooting
Out of Memory Errors
-
Reduce chunk size:
-
Enable more aggressive memory handling:
- Use external storage earlier:
Performance Issues
- Check disk I/O speed
- Enable compression for text data
- Use memory-based external storage:
Checkpoint Recovery
Requirements
- PHP 8.1 or higher
- ext-json
- ext-mbstring
Optional Extensions
- ext-apcu for faster caching
- ext-redis for distributed operations
- ext-zlib for compression
Contributing
Please see CONTRIBUTING.md for details.
License
The Apache 2.0 License. Please see LICENSE for details.
All versions of spacetime with dependencies
psr/log Version ^3.0
psr/container Version ^2.0
psr/simple-cache Version ^3.0