CodeIgniter Forums
cURL library - where can I get? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: cURL library - where can I get? (/showthread.php?tid=62631)



cURL library - where can I get? - vertisan - 08-07-2015

Hi!

Where can I get cURL library for CI3? I need it, because I want try to integrate SMSAPI.com
The best will be, when the library was the latest


RE: cURL library - where can I get? - eliorr - 08-07-2015

(08-07-2015, 09:31 AM)vertisan Wrote: Hi!

Where can I get cURL library for CI3? I need it, because I want try to integrate SMSAPI.com
The best will be, when the library was the latest


Simply try taking the PGP class library from : https://github.com/php-curl-class/php-curl-class 
and make it a  CI library  :-) 


RE: cURL library - where can I get? - mwhitney - 08-07-2015

https://github.com/philsturgeon/codeigniter-curl

As noted on the page, it is no longer maintained, but I'm not aware of any specific issues in CI3. Links to alternatives are also included on the page, though you'll probably have to write a little code to adapt them for use in your application.


RE: cURL library - where can I get? - ivantcholakov - 08-07-2015

I have adopted this library, with minor changes https://github.com/ivantcholakov/starter-public-edition-3/blob/v3.0.55/platform/application/libraries/Curl.php


RE: cURL library - where can I get? - solidcodes - 08-07-2015

thanks for the links guys.
guzzle and requests cool...


RE: cURL library - where can I get? - ivantcholakov - 08-08-2015

Guzzle 6 requires PHP 5.5. It is easy to be installed with Composer. But it needs to load some files immediately, so on PHP 5.3 it will cause PHP parsing error nevertheless you use this component or not.

Requests 1.6.1 requires PHP 5.2. It is lighter. For those who use the Curl library before and the Rest client library by Phil Sturgeon, Requests would be more familiar. It can be installed with Composer, I have chosen a manual installation, it is possible.


RE: cURL library - where can I get? - ivantcholakov - 08-10-2015

I have installed everything within one project: https://github.com/ivantcholakov/codeigniter-restserver-test


RE: cURL library - where can I get? - ivantcholakov - 11-23-2016

I've just seen another interesting project: https://github.com/php-http/httplug "HTTPlug, the HTTP client abstraction for PHP."
If you are concerned not to be bound to a specific http-client implementation, have a look at it.


RE: cURL library - where can I get? - visualsol - 11-30-2016

I've been playing with guzzle lately.. it is so EASY to use, and seems like it will be around for quite some time. 
Example steps below to do a typical authenticate to a site  (from a library I'm working on)..
Bob
Ignition-Go


Steps: 
load library referencing guzzle, init the client, optionally set cookies, do HTTP/REST call(s), get response(s)
Code:
    $this->ci->load->library('guzzle'); /* from Ignition Go */

    $this->client = new GuzzleHttp\Client([
      'base_uri'=> $this->baseUrl /* base url you are using */,
    ' 'verify' => false /* for testing */
    ]);

        /* for session cookies */
    $this->cookieJar = new GuzzleHttp\Cookie\FileCookieJar($this->cookieFilePath,TRUE);

    $response = null;
        $parms = array('cookies'=> $this->cookieJar,
            'form_params' => array()  );
        $data['client_id'] = $this->client_id;
    $data['secret'] = $this->secret;
        $parms['form_params'] = $data;
       
        try {
          switch ($method) {
      case 'post':
        $response = $this->client->request( 'POST', $service, $parms);
            break;
      case 'get':
        $response = $this->client->request( 'GET', $service, $parms);
        break;
...

    echo $response->getStatusCode(); // 200
    echo $response->getReasonPhrase(); // OK
    echo $response->getProtocolVersion(); // 1.1
    echo $response->getBody();
    return json_decode($response->getBody(), true);
    }
catch (GuzzleHttp\Exception\BadResponseException $e) {
    $response = $e->getResponse();
    $responseBodyAsString = $response->getBody()->getContents();
    print_r($responseBodyAsString);
  }



RE: cURL library - where can I get? - cartalot - 11-30-2016

Learn how to use Curl. Its not that difficult. Once you have the basics down you can use the same template. You can put Curl code anywhere in codeigniter it does not have to be loaded like a library. I would also suggest learning how to use Guzzle - but learn Curl first because its in so many libraries and you don't want to be intimidated by it. Try and read the PHP Web Services book by Lorna Mitchell. Anyway here's a basic example of getting something thats been json encoded:

PHP Code:
 // set HTTP header for json 
$headers = array('Content-Type: application/json',);

// set the url for the service you are contacting 
// example has an id that is passed 
$url 'https://website.com/returnsomething/'.$id 

// Open connection
$ch curl_init();

// Set the url, number of GET vars, GET data
curl_setopt($chCURLOPT_URL$url);
curl_setopt($chCURLOPT_POSTfalse);
curl_setopt($chCURLOPT_HTTPHEADER$headers);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue );

// this is controversial 
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);

// Execute request
$result curl_exec($ch);

// Close connection
curl_close($ch);

// get the result and parse to JSON
$something json_decode($result);

  if(isset($something)){ return $something ; }

  else { return FALSE ; }