athlon1600/php-curl-client
Lightweight, extensible PHP cURL client (PHP 7.3–8.4). Make GET/POST or fully customized requests and always receive a standardized Response with status, body, error, and typed cURL info for IDE autocomplete.
Pros:
setCurlOption() and setUserAgent(), allowing alignment with Laravel’s HTTP client configurations (e.g., default headers, timeouts).Psr\Http\Message) would align with Laravel’s ecosystem (e.g., HTTP clients in Laravel 10+).Cons:
Illuminate\Http\Client or Symfony\Component\HttpClient). May necessitate wrapper classes for consistency.setStorageDirectory() may not suffice for complex Laravel session management (e.g., Illuminate\Session).Laravel-Specific Considerations:
register() method to bind the client to the container (e.g., app()->bind('curlClient', fn() => new Client())).Curl) for fluent syntax (e.g., Curl::get()), mirroring Laravel’s Http facade.config/http.php for shared settings (e.g., timeouts, default headers).Http::fake() alternatives via mocking the Client class).Dependencies:
ext-json for dev), reducing versioning risks.Low to Medium:
Response object simplifies error handling (e.g., $response->error), but lacks Laravel’s Exception hierarchy (e.g., HttpClientException).Mitigation:
HttpClientContract) to isolate Laravel-specific logic.Http::asForm() for form data) or middleware for retries/logging.setStorageDirectory()?Http::fake() alternatives)?Laravel Ecosystem:
Http client for non-PSR-7 use cases (e.g., legacy systems, simple requests).php artisan curl:fetch).@curlClient in Blade or controllers).Complementary Tools:
php-curl-client for non-PSR-7 needs while leveraging Laravel’s Http client for PSR-compliant workflows.CurlMiddleware) to bridge gaps (e.g., logging, retries).php-curl-client in a feature branch.Http client behavior.GET/POST requests in controllers/services.request() method.config/http.php:
'curl' => [
'timeout' => env('CURL_TIMEOUT', 30),
'user_agent' => env('CURL_USER_AGENT', 'Laravel'),
],
$this->app->singleton(Client::class, fn() => tap(new Client(), function ($client) {
$client->setUserAgent(config('http.curl.user_agent'));
$client->setCurlOption(CURLOPT_TIMEOUT, config('http.curl.timeout'));
}));
CurlInfo aids developer experience.get(), post()).try-catch for $response->error).BrowserClient for scraping/testing.Event system (e.g., log requests).Http client.ApiClient extending Client).$response->error and $response->info simplify debugging.$response->info on failures).custom_options + default_options order is correct (fixed in v1.1.2).How can I help you explore Laravel packages today?