Download the PHP package egyjs/progressive-json-php without Composer
On this page you can find all versions of the php package egyjs/progressive-json-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download egyjs/progressive-json-php
More information about egyjs/progressive-json-php
Files in egyjs/progressive-json-php
Package progressive-json-php
Short Description Framework-agnostic Progressive JSON Streamer for PHP - breadth-first JSON streaming with placeholders, inspired by Dan Abramov's Progressive JSON.
License MIT
Informations about the package progressive-json-php
Progressive JSON Streaming for PHP APIs
TL;DR: Progressive JSON Streaming sends data incrementally to show users page structure instantly while slow API calls complete in the background.
Stream JSON responses progressively to improve user experience. Send page structure instantly, then fill in slow data as it becomes available. Perfect for dashboards, homepages, and APIs mixing fast cached data with slow database queries.
Perfect for dashboards, homepages, and any API where some data loads fast (cache) and some loads slow (database/external APIs).
The Problem
The Solution
Result: User sees page structure in 50ms, then data appears as it loads.
Installation
Quick Start
1. Basic Usage
2. What the Client Receives
3. Frontend Integration
When to Use
โ Good for:
- Dashboard APIs with multiple data sources
- Homepage APIs mixing cached and database data
- Any API where some data is fast, some is slow
- Mobile apps (reduces HTTP requests)
โ Skip if:
- All your data loads fast (<100ms)
- Using WebSockets/Server-Sent Events
- Simple APIs with single data source
Framework Integration
Laravel
Symfony
API Reference
Core Methods
Configuration Methods
setMaxDepth(int $depth): self
Set maximum nesting depth for structure walking (default: 50).
Output Methods
stream(): Generator
Returns a Generator that yields JSON chunks.
send(): void
Streams the response directly to output buffer (for pure PHP).
asResponse(): StreamedResponse
Returns a Symfony StreamedResponse for framework integration.
Utility Methods
getPlaceholderKeys(): array
Get all registered placeholder keys.
hasPlaceholder(string $key): bool
Check if a placeholder exists.
removePlaceholder(string $key): self
Remove a specific placeholder.
clearPlaceholders(): self
Remove all placeholders.
getStructure(): array
Get the current structure template.
๐ Common Use Cases
Admin Dashboard
E-commerce Product Page
Social Media Feed
๐ฏ Advanced Features
Error Handling
Errors are automatically serialized to JSON:
Advanced Usage
Performance Optimization
Security
HTTP Headers
The library automatically sets streaming-optimized headers:
Common Use Cases
Dashboard API
E-commerce Product Page
Troubleshooting
| Problem | Solution |
|---|---|
| Stream cuts off early | Call ob_end_clean() before streaming |
| Memory errors | Use pagination in resolvers |
| Timeout errors | Increase max_execution_time |
| CORS issues | Set CORS headers before streaming |
| Parsing fails | Validate JSON in resolvers |
Debug Mode
๐ Resources & Inspiration
- Concept Origin: Dan Abramov's Progressive JSON
- React Server Components: Uses the same streaming pattern
- Similar Concepts: Progressive JPEG loading, HTTP/2 Server Push
- Use Cases: Netflix UI, Facebook feeds, Google search results
๐งช Testing
This library comes with comprehensive PHPUnit tests to ensure reliability and maintainability.
Running Tests
Test Coverage
The test suite includes:
- โ Basic functionality tests
- โ Error handling and edge cases
- โ Nested structure handling
- โ Stream generation and output
- โ Symfony integration tests
- โ Configuration and validation tests
- โ Laravel installation tests (v9.x - v12.x)
Coverage reports are generated in build/coverage-html/ when running with coverage.
Laravel Installation Tests
We provide comprehensive installation tests for Laravel versions 9.x through 12.x:
These tests verify:
- Package installation via Composer
- Autoloading and integration with Laravel
- Performance and clean removal
See docs/LARAVEL_INSTALLATION_TESTS.md for detailed information.
Continuous Integration
GitHub Actions automatically runs tests on:
- PHP 8.1, 8.2, 8.3, and 8.4
- Laravel 9.x, 10.x, 11.x, and 12.x combinations
- Push and Pull Request events
- Multiple operating systems
- Weekly scheduled runs
๐ค Contributing
We welcome contributions from everyone! Please read our Contributing Guide for detailed information on how to get started.
Quick Start:
- Fork the repository
- Create a feature branch:
git checkout -b feature/name - Commit changes:
git commit -m 'Add feature' - Push to branch:
git push origin feature/name - Open a Pull Request
Important:
- Read our Code of Conduct
- Follow our Contributing Guidelines
- Include tests for new features
- Update documentation as needed
For detailed setup instructions, coding standards, and development workflow, see CONTRIBUTING.md.
๐ License
MIT License. See LICENSE for details.
Author
AbdulRahman El-zahaby (@egyjs)
๐ง [email protected]
๐ GitHub: @egyjs
๐ Acknowledgments
- Symfony HttpFoundation for streaming response utilities
- The PHP community for feedback and contributions
Made with โค๏ธ by egyjs for the PHP community