PHP code example of mohebbi / curl
1. Go to this page and download the library: Download mohebbi/curl library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mohebbi / curl example snippets
ohebbiCurl\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;
}