mohebbi/curl
最新稳定版本:v1.0.0
Composer 安装命令:
composer require mohebbi/curl
包简介
A comprehensive, fluent, and object-oriented cURL library for PHP, supporting single and multi-requests with advanced options.
README 文档
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.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-12