PHP code example of jabranr / php-curl

1. Go to this page and download the library: Download jabranr/php-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/ */

    

jabranr / php-curl example snippets




abran\HttpUtil\HttpCurlRequest;
use Jabran\HttpUtil\Exception\HttpCurlException;

# Start new cURL request
$curl = new HttpCurlRequest('http://jabran.me');



# Set options - method 1
$curl->setOption(CURLOPT_RETURNTRANSFER, true);
$curl->setOption(CURLOPT_FOLLOWLOCATION, true);

# Set options - method 2
$curl->setOptions(array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true
));

# Execute request, get response and close connection
try {
    $response = $curl->execute();
} catch(HttpCurlException $e) {
    $curl->getErrorCode(); // -> cURL error number
    $curl->getErrorMessage(); // -> cURL error message
    
    # OR
    
    $e->getMessage(); // -> cURL error: [ErrorCode] ErrorMessage
}

# OR get more info and close connection manually
try {
    $response = $curl->execute(false);
} catch(HttpCurlException $e) { }

# Get response later
$response = $curl->getResponse();

# 
$info = $curl->getInfo();

# Close request
$curl->close();

$curl->execute(false);
$curl->getInfo($option = null);
$curl->close();

$curl->getError();

$curl->getErrorCode();

$curl->getErrorMessage();

$curl->getHttpCode();

$curl->getTotalTime();

$curl->getResponse();
shell
$ composer