Skip to content

Mohammadreza-73/Phoxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

73 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Phoxy

PHP Proxy Server with Caching

A lightweight, flexible PHP proxy server with intelligent caching capabilities for web content. Designed to improve website performance by caching HTML and JSON resources.

Important

This proxy server is designed for development and moderate production use. For high-traffic applications, consider additional scaling strategies and monitoring.

Features

  • πŸš€ High Performance: Caches responses to reduce server load and improve response times
  • πŸ“¦ Content-Type Aware: Intelligently caches HTML and JSON
  • ⚑ Configurable TTL: Different cache durations for different content types
  • πŸ”’ Security: Domain blacklisting and request validation
  • πŸ“Š Cache Statistics: Built-in monitoring and statistics generation
  • πŸ› οΈ Easy Configuration: Simple setup and customization

Supported Content Types

Content Type Default TTL Description
HTML 1 Hour Web pages and HTML content
JSON 1 Hour API responses and data

Installation and Running

1. Clone the repository

git clone https://github.com/Mohammadreza-73/Phoxy.git
cd Phoxy

2. Ensure PHP requirements

# Check if cURL is enabled
php -m | grep curl

3. Ensure cache directory permissions

chmod 755 cache/
chmod 755 cache/*/

4. Serve server

php -S localhost:8000

Configuration

Edit src/config/cache.php to customize the proxy behavior:

Usage

Basic GET Request

// Frontend JavaScript usage
fetch('/proxy.php?url=' + encodeURIComponent('https://example.com/api/data'))
    .then(response => response.json())
    .then(data => console.log(data));

POST Request

// Sending POST data through proxy
fetch('/proxy.php', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        url: 'https://api.example.com/submit',
        data: { /* your payload */ }
    })
});

API Reference

Query Parameters

Parameter Required Description
url Yes The target URL to proxy (URL encoded)

Response Headers

Header Description
X-Proxy-Cache HIT if served from cache, MISS if fetched fresh
Access-Control-Allow-Origin * (CORS enabled)

Security Considerations

  1. Domain Blacklisting: Block specific domains
  2. Content Length Limits: Prevents large file attacks
  3. Timeout Protection: Limits request duration
  4. CORS Headers: Proper cross-origin handling
  5. Header Filtering: Removes sensitive headers from responses

Example Use Cases

  • API Aggregation: Combine multiple APIs with caching
  • Content Mirroring: Cache external resources for faster access
  • Cross-Origin Requests: bypass CORS limitations for development
  • Performance Optimization: Reduce load times for external resources
  • Offline Development: Cache responses for development without internet

File Structure

caching-proxy-server/
β”œβ”€β”€ cache/               # Cache storage directory
β”œβ”€β”€ logs/                # Store logs in `app.log`
β”œβ”€β”€ src/                 # Source directory
β”‚   β”œβ”€β”€ config/          # Cache configuration settings
β”‚   β”œβ”€β”€ helpers/         # Helper functions
β”‚   β”œβ”€β”€ FileCache.php    # Class to handle cache files
β”‚   β”œβ”€β”€ ProxyServer.php  # Class to manage Proxy Server
β”‚   └── Response.php     # Class to handle HTTP resposne
β”œβ”€β”€ .editorconfig        # config for editors
└── index.php            # Serve project

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

  1. Check the issues page
  2. Create a new issue with detailed description

License

This project is licensed under the MIT License - see the License File file for details.

About

Caching server that caches responses from other servers.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors

Languages