amirxd/php-ultra-request

A powerful HTTP client library for PHP

Maintainers

Package info

github.com/amirxdcy4455/UltraRequest

pkg:composer/amirxd/php-ultra-request

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-07-08 14:12 UTC

This package is auto-updated.

Last update: 2026-07-08 14:18:07 UTC


README

PHP Version License Packagist

A powerful, feature-rich HTTP client library for PHP with full cURL support, cookie management, proxy handling, authentication, and advanced file downloading capabilities.

โœจ Features

  • ๐Ÿ”Œ Full cURL Integration - Leverages PHP's cURL extension for maximum performance
  • ๐Ÿช Cookie Management - Full cookie jar with persistence, parsing, and domain/path matching
  • ๐ŸŒ Proxy Support - HTTP, HTTPS, SOCKS4, SOCKS5 proxies with authentication
  • ๐Ÿ” Authentication - Basic, Bearer Token, and API Key authentication methods
  • ๐Ÿ“ฅ Advanced Downloader - Resume support, progress tracking, console progress bar, retry mechanism
  • ๐Ÿ”„ Manual Redirect Handling - RFC 7231 compliant, preserves method semantics (301/302/307/308)
  • ๐Ÿงน Clean Architecture - PSR-4 compliant, fully object-oriented with interfaces
  • โšก Fluent Interface - Method chaining for elegant API usage
  • ๐Ÿงช JSON Support - Automatic JSON encoding/decoding with type safety
  • ๐Ÿ”’ SSL Verification - Optional SSL verification for development/secure environments

๐Ÿ“‹ Requirements

  • PHP 8.0 or higher
  • cURL extension (ext-curl)
  • JSON extension (ext-json)

๐Ÿš€ Installation

Via Composer

composer require amirxd/php-ultra-request

Manual Installation

git clone https://github.com/amirxd/php-ultra-request.git
cd php-ultra-request
composer install

๐Ÿ“– Quick Start

Basic GET Request

<?php

require_once 'vendor/autoload.php';

use Amirxd\UltraRequest\UltraRequest;

$http = new UltraRequest();

$response = $http->get('https://api.github.com/users/amirxd');

if ($response->isSuccessful()) {
    $data = $response->getJson();
    echo "User: " . ($data['name'] ?? 'N/A') . "\n";
    echo "Bio: " . ($data['bio'] ?? 'N/A') . "\n";
}

POST Request with JSON

<?php

use Amirxd\UltraRequest\UltraRequest;

$http = new UltraRequest();

$data = [
    'title' => 'New Post',
    'body' => 'Lorem ipsum dolor sit amet',
    'userId' => 1
];

$response = $http->post(
    'https://jsonplaceholder.typicode.com/posts',
    json_encode($data),
    ['Content-Type' => 'application/json']
);

if ($response->isSuccessful()) {
    $result = $response->getJson();
    echo "Created post ID: " . $result['id'] . "\n";
}

Using the Fluent Request Builder

<?php

use Amirxd\UltraRequest\Request\Request;
use Amirxd\UltraRequest\Client\Client;

$client = new Client();
$request = Request::post('https://api.example.com/users')
    ->withHeader('X-API-Key', 'your-api-key-here')
    ->withJson(['name' => 'John Doe', 'email' => 'john@example.com'])
    ->withQueryParams(['source' => 'web']);

$response = $client->send($request);

๐Ÿ” Authentication

Basic Authentication

<?php

use Amirxd\UltraRequest\UltraRequest;

$http = new UltraRequest();
$client = $http->getClient()->withBasicAuth('username', 'password');

$response = $client->send(
    Request::get('https://api.example.com/protected')
);

Bearer Token (OAuth2)

<?php

use Amirxd\UltraRequest\UltraRequest;

$http = new UltraRequest();
$client = $http->getClient()->withBearerAuth('your-token-here');

$response = $client->send(
    Request::get('https://api.example.com/user')
);

API Key Authentication

<?php

use Amirxd\UltraRequest\Auth\AuthManager;
use Amirxd\UltraRequest\Client\Client;

$auth = new AuthManager();
$auth->apiKey('X-API-Key', 'your-api-key', 'header');

$client = (new Client())->withAuth(function($manager) {
    $manager->apiKey('X-API-Key', 'your-api-key', 'header');
});

$response = $client->send(
    Request::get('https://api.example.com/protected')
);

Using AuthManager with Fluent API

<?php

use Amirxd\UltraRequest\Client\Client;

$client = new Client();
$client = $client->withAuth(function($auth) {
    $auth->basic('username', 'password');
    // OR
    $auth->bearer('your-token-here');
    // OR
    $auth->apiKey('X-API-Key', 'your-key', 'header');
});

๐Ÿช Cookie Management

Basic Cookie Usage

<?php

use Amirxd\UltraRequest\Cookie\CookieJar;
use Amirxd\UltraRequest\Client\Client;
use Amirxd\UltraRequest\Request\Request;

$cookieJar = new CookieJar('cookies.json', true); // Auto-load from file
$client = (new Client())->withCookieJar($cookieJar);

// Cookies will be automatically saved and loaded
$response = $client->send(Request::get('https://example.com'));

// Manually set a cookie
$cookieJar->setCookie('session_id', 'abc123', [
    'domain' => '.example.com',
    'path' => '/',
    'expires' => time() + 3600,
    'secure' => true,
    'httpOnly' => true
]);

// Get all cookies as header string
$cookieHeader = $cookieJar->toHeader();

Cookie Persistence

<?php

// Save cookies to file
$cookieJar = new CookieJar('cookies.json');
$cookieJar->setCookie('user', 'john_doe');

// Load existing cookies
$cookieJar = new CookieJar('cookies.json', true);
echo $cookieJar->getCookie('user')->getValue(); // john_doe

๐ŸŒ Proxy Support

HTTP/HTTPS Proxy

<?php

use Amirxd\UltraRequest\Proxy\Proxy;
use Amirxd\UltraRequest\Client\Client;

$proxy = new Proxy('http://proxy.example.com:8080');

// With authentication
$proxy = (new Proxy('http://proxy.example.com:8080'))
    ->withAuth('username', 'password');

$client = (new Client())->setProxy($proxy);

SOCKS Proxy

<?php

use Amirxd\UltraRequest\Proxy\Proxy;

// SOCKS5 proxy
$proxy = new Proxy('socks5://socks.example.com:1080');

// SOCKS4 proxy
$proxy = new Proxy('socks4://socks.example.com:1080');

$client = (new Client())->setProxy($proxy);

Proxy String Formats

// All these formats are supported:
$proxy = new Proxy('http://proxy.example.com:8080');
$proxy = new Proxy('proxy.example.com:8080'); // Defaults to HTTP
$proxy = new Proxy('https://proxy.example.com:443');
$proxy = new Proxy('socks5://user:pass@socks.example.com:1080');

๐Ÿ“ฅ Advanced File Downloader

Basic Download

<?php

use Amirxd\UltraRequest\File\Downloader;
use Amirxd\UltraRequest\Client\Client;

$downloader = new Downloader(
    'https://example.com/file.zip',
    '/path/to/save/file.zip'
);

$client = new Client();
$client->download($downloader);

Download with Progress Bar (Console)

<?php

use Amirxd\UltraRequest\File\Downloader;
use Amirxd\UltraRequest\Client\Client;

$downloader = new Downloader(
    'https://example.com/large-file.zip',
    './downloads/file.zip'
);

// Enable console progress bar
$downloader = $downloader->withConsoleProgress(50);

$client = new Client();
$client->download($downloader);

// Output: [โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘] 75.0% | 15.3 MB / 20.4 MB | 2.1 MB/s | ETA: 00:24

Download with Custom Progress Callback

<?php

use Amirxd\UltraRequest\File\Downloader;
use Amirxd\UltraRequest\Client\Client;

$downloader = new Downloader(
    'https://example.com/file.zip',
    './downloads/file.zip'
);

$downloader = $downloader->withProgress(function($progress) {
    echo sprintf(
        "Downloaded: %s / %s (%.1f%%) | Speed: %s | ETA: %s\n",
        $progress['downloaded_formatted'],
        $progress['total_formatted'],
        $progress['percent'],
        $progress['speed_formatted'],
        $progress['eta_formatted']
    );
});

$client = new Client();
$client->download($downloader);

Resume Download

<?php

use Amirxd\UltraRequest\File\Downloader;
use Amirxd\UltraRequest\Client\Client;

$downloader = new Downloader(
    'https://example.com/large-file.zip',
    './downloads/file.zip'
);

// Enable resume support
$downloader = $downloader->withResume(true);

$client = new Client();
$client->download($downloader); // Will resume if file exists

Download with Retry Mechanism

<?php

use Amirxd\UltraRequest\File\Downloader;
use Amirxd\UltraRequest\Client\Client;

$downloader = new Downloader(
    'https://example.com/file.zip',
    './downloads/file.zip'
);

// Retry up to 3 times with 2-second delay between attempts
$downloader = $downloader->withRetries(3, 2);

$client = new Client();
$client->download($downloader);

Complete Download Example

<?php

use Amirxd\UltraRequest\File\Downloader;
use Amirxd\UltraRequest\Client\Client;

try {
    $downloader = new Downloader(
        'https://example.com/large-file.zip',
        './downloads/large-file.zip'
    );
    
    $downloader = $downloader
        ->withResume(true)
        ->withConsoleProgress(50)
        ->withRetries(3, 2)
        ->withOverwrite(false) // Don't overwrite if exists (unless resuming)
        ->withHeader('User-Agent', 'PHP Ultra Request')
        ->withChunkSize(1024 * 1024 * 2); // 2MB chunks
    
    $client = new Client();
    $success = $client->download($downloader);
    
    if ($success) {
        echo "\nโœ… Download completed!\n";
    }
    
} catch (\Exception $e) {
    echo "\nโŒ Download failed: " . $e->getMessage() . "\n";
}

โš™๏ธ Advanced Client Configuration

Custom Headers

<?php

use Amirxd\UltraRequest\Client\Client;
use Amirxd\UltraRequest\Request\Request;

$client = new Client();
$client = $client->withAuth(function($auth) {
    $auth->bearer('your-token');
});

$request = Request::get('https://api.example.com/users')
    ->withHeader('X-Custom-Header', 'custom-value')
    ->withHeader('Accept', 'application/json');

$response = $client->send($request);

Timeout Configuration

<?php

use Amirxd\UltraRequest\Client\Client;
use Amirxd\UltraRequest\Request\Request;

$client = (new Client())
    ->withTimeout(60)           // Total timeout: 60 seconds
    ->withConnectTimeout(10);   // Connection timeout: 10 seconds

$response = $client->send(Request::get('https://slow-api.example.com'));

SSL Verification Control

<?php

use Amirxd\UltraRequest\Client\Client;

// Enable SSL verification (default, recommended for production)
$client = (new Client())->withSSL(true);

// Disable SSL verification (useful for development)
$client = (new Client())->withSSL(false);

Custom cURL Options

<?php

use Amirxd\UltraRequest\Client\Client;
use Amirxd\UltraRequest\Request\Request;

$client = (new Client())
    ->withCurlOption(CURLOPT_USERAGENT, 'MyCustomBot/1.0')
    ->withCurlOption(CURLOPT_MAXREDIRS, 5)
    ->withCurlOption(CURLOPT_REFERER, 'https://google.com');

$response = $client->send(Request::get('https://example.com'));

๐Ÿ” Response Handling

Response Methods

<?php

use Amirxd\UltraRequest\UltraRequest;

$http = new UltraRequest();
$response = $http->get('https://api.example.com/data');

// Get status code
$statusCode = $response->getStatusCode(); // 200

// Get response body
$body = $response->getBody(); // Raw string

// Get JSON decoded data
$data = $response->getJson(true); // Associative array
$data = $response->getJson(false); // Object

// Check response status
if ($response->isSuccessful()) {
    // 2xx responses
} elseif ($response->isRedirect()) {
    // 3xx responses
} elseif ($response->isClientError()) {
    // 4xx responses
} elseif ($response->isServerError()) {
    // 5xx responses
}

// Get specific header
$contentType = $response->getHeader('Content-Type');
$allHeaders = $response->getHeaders();

// Get cURL info
$info = $response->getInfo(); // URL, total_time, etc.

๐Ÿงช Testing

Run Tests

# Download a test file
php tests/DownloadTest.php

# Run the basic test script
php tests/UltraRequestTest.php

Example Test Script

<?php
// tests/UltraRequestTest.php

require_once 'vendor/autoload.php';

use Amirxd\UltraRequest\UltraRequest;

echo "๐Ÿงช Testing UltraRequest...\n\n";

try {
    $http = new UltraRequest();
    
    // Test GET
    echo "๐Ÿ“ก Testing GET request...\n";
    $response = $http->get('https://httpbin.org/get');
    echo "โœ… Status: " . $response->getStatusCode() . "\n";
    
    // Test POST
    echo "\n๐Ÿ“ก Testing POST request...\n";
    $response = $http->post('https://httpbin.org/post', 
        json_encode(['test' => 'success']),
        ['Content-Type' => 'application/json']
    );
    echo "โœ… Status: " . $response->getStatusCode() . "\n";
    
    echo "\nโœจ All tests passed!\n";
    
} catch (\Exception $e) {
    echo "โŒ Error: " . $e->getMessage() . "\n";
    exit(1);
}

๐Ÿ“ Directory Structure

php-ultra-request/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ Auth/
โ”‚   โ”‚   โ”œโ”€โ”€ ApiKeyAuth.php
โ”‚   โ”‚   โ”œโ”€โ”€ AuthInterface.php
โ”‚   โ”‚   โ”œโ”€โ”€ AuthManager.php
โ”‚   โ”‚   โ”œโ”€โ”€ BasicAuth.php
โ”‚   โ”‚   โ””โ”€โ”€ BearerAuth.php
โ”‚   โ”œโ”€โ”€ Client/
โ”‚   โ”‚   โ””โ”€โ”€ Client.php
โ”‚   โ”œโ”€โ”€ Cookie/
โ”‚   โ”‚   โ”œโ”€โ”€ Cookie.php
โ”‚   โ”‚   โ”œโ”€โ”€ CookieInterface.php
โ”‚   โ”‚   โ”œโ”€โ”€ CookieJar.php
โ”‚   โ”‚   โ””โ”€โ”€ CookieJarInterface.php
โ”‚   โ”œโ”€โ”€ File/
โ”‚   โ”‚   โ””โ”€โ”€ Downloader.php
โ”‚   โ”œโ”€โ”€ Proxy/
โ”‚   โ”‚   โ”œโ”€โ”€ Proxy.php
โ”‚   โ”‚   โ””โ”€โ”€ ProxyInterface.php
โ”‚   โ”œโ”€โ”€ Request/
โ”‚   โ”‚   โ”œโ”€โ”€ Request.php
โ”‚   โ”‚   โ””โ”€โ”€ RequestInterface.php
โ”‚   โ”œโ”€โ”€ Response/
โ”‚   โ”‚   โ”œโ”€โ”€ HttpResponse.php
โ”‚   โ”‚   โ””โ”€โ”€ ResponseInterface.php
โ”‚   โ””โ”€โ”€ UltraRequest.php
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ UltraRequestTest.php
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ basic-usage.php
โ”‚   โ”œโ”€โ”€ download-example.php
โ”‚   โ””โ”€โ”€ cookie-example.php
โ”œโ”€โ”€ composer.json
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ .gitignore

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

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

Coding Standards

  • Follow PSR-12 coding standards
  • Add tests for new features
  • Update documentation accordingly
  • Ensure PHP 8.0+ compatibility

๐Ÿ“„ License

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

๐Ÿ™ Acknowledgments

  • Built with PHP's powerful cURL extension
  • Inspired by Guzzle HTTP Client
  • RFC 7231 compliant for HTTP/1.1

๐Ÿ“ซ Contact

๐ŸŒŸ Star the Project

If you find this library useful, please consider giving it a โญ on GitHub!

Made with โค๏ธ by Amirxd