MagicCurl

MagicCurl PHP Library

MagicCurl PHP Library

Stable PHP Version Require License Downloads

Prerequisites

  • A minimum of PHP 7.3 upto 8.0
  • PHP cURL extension

Installation

  • If your project using composer, run the below command
composer require enishant/magiccurl:1.0
  • If you are not using composer, download the latest release from the releases section. You should download the magiccurl.zip file. After that, include MagicCurl.php in your application and you can use the MagicCurl methods by creating it’s instance.

Note: This PHP library follows the following practices:

  • Namespaced under Enishant\MagicCurl
  • Options are passed as an array instead of multiple arguments wherever possible
  • All requests and responses are communicated using PHP CURL extension

Basic Usage

Instantiate the MagicCurl php instance with/without providing an options.

use Enishant\MagicCurl\MagicCurl;

$client = new MagicCurl;

Options

  • create_log – Creates log for user agent, header, request and response.
  • log_path – Provide log file path.
  • debug – Display all php errors.
  • user_agent – Custom User Agent name.

Create log file, update onwership & permissions

sudo touch /path/to/magiccurl.log
sudo chown www-data:www-data /path/to/magiccurl.log
sudo chmod 644 /path/to/magiccurl.log
use Enishant\MagicCurl\MagicCurl;

$options = [
    'create_log' => true,
    'log_path'   => '/path/to/magiccurl.log',
    'debug'      => true,
    'user_agent' => 'MagicCurl/1.0'
];

$client = new MagicCurl( $options );

The resources can be accessed via the $client object. All the methods invocations follows the following pattern

    // $client->function() to access the methods
    
    //Example - Request with GET method
    $client->get($url);
    
    //Example - Request with POST method
    $headers = [
      'X-CUSTOM-HEADER-ONE: Value 1',
      'X-CUSTOM-HEADER-TWO: Value 2',
    ];
    $payload = ['data'=>'in array'];
    $client->post($url, $headers, $payload);

License

The MagicCurl PHP Library is released under the MIT License. See LICENSE file for more details.

Nishant Vaity

Knowledgeable and skilled Technology Lead with an ability of software development and supervision. Possess a Bachelor of Science (BS) in Information Technology along with 11+ years of experience with hands-on coding and team management. By profession, I am a Software Engineer, Technology Mentor & Entrepreneur. Passionate about the technologies I use and always eager to share & learn more from that passion.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.