mohebbi / curl
A comprehensive, fluent, and object-oriented cURL library for PHP, supporting single and multi-requests with advanced options.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/mohebbi/curl
Requires
- php: ^7.4|^8.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.75
- pestphp/pest: ^1.23
- phpunit/phpunit: ^9.5
This package is not auto-updated.
Last update: 2025-12-26 14:45:22 UTC
README
MohebbiCurl is a powerful, object-oriented, and fluent cURL library for PHP. It simplifies the process of making HTTP requests, handling responses, and managing errors, whether you're dealing with a single request or hundreds of concurrent ones.
This library is designed to be both easy to use for beginners and powerful enough for advanced users, providing a clean and modern API for all your cURL needs.
Features
- ✅ Fluent, chainable interface for building requests.
- ✅ Support for both single and concurrent (multi) requests.
- ✅ Robust, object-oriented error and exception handling with detailed information.
- ✅ Effortless JSON and form data handling.
- ✅ Easy file uploads and downloads.
- ✅ Full control over headers, cookies, proxies, and authentication.
- ✅ Advanced options management with built-in presets (e.g., for APIs, scraping).
- ✅ Well-structured and predictable
CurlRequestandCurlResponseobjects. - ✅ Fully compatible with modern PHP and Composer.
Installation
You can install the library via Composer.
composer require mohebbi/curl
Basic Usage
Making a simple GET request is straightforward. The fluent interface allows you to build your request step-by-step.
<?php require_once __DIR__ . '/vendor/autoload.php'; use MohebbiCurl\MohebbiCurl; use MohebbiCurl\CurlException; $curl = new MohebbiCurl(); try { // Make a simple GET request $response = $curl->get('[https://api.github.com/users/google](https://api.github.com/users/google)'); // Check the HTTP status code if ($response->isSuccess()) { // Get response body as an associative array $data = $response->json(); echo "Google's public repositories: " . $data['public_repos'] . PHP_EOL; echo "Response Total Time: " . $response->getTotalTime() . " seconds." . PHP_EOL; } else { echo "Request failed with HTTP code: " . $response->getHttpCode() . PHP_EOL; } } catch (CurlException $e) { // Handle cURL-level errors (e.g., connection timeout) echo "cURL Error: " . $e->getMessage() . PHP_EOL; }
More Examples
For more advanced use cases, please see the examples/ directory:
- POST Requests & File Uploads:
examples/file_upload.php - Concurrent Requests:
examples/multi_requests.php - Advanced Configuration:
examples/advanced_options.php
Testing
To run the test suite, you need to install the development dependencies and then run PHPUnit.
# Install dev dependencies composer install # Run tests composer test
Contributing
Contributions are welcome! Please feel free to submit a pull request or create an issue for bugs, questions, or feature requests.
License
The MohebbiCurl library is open-source software licensed under the MIT license.