PHP code example of wykleph / curl

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

    

wykleph / curl example snippets


$curler = new Curler('https://github.com/');

$curler->post('fname', 'John')
    ->post('lname', 'Doe')
;
$curler->postArray(['fname'=>'John', 'lname'=>'Doe']);

$curler->get();

$curler->header('Connection', 'keep-alive')
    ->header('Host', 'github.com')
;
$curler->headerArray(['Connection'=>'keep-alive', 'Host'=>'github.com']);

$ua = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0';

$curler->userAgent($ua)
    ->referer('http://github.com');

$curler->cookieJar('SomeDirectory/testCookie');

$curler->followRedirects();

$curler->compressedResponse()

$curler->upload('file', 'filepath');

$curler->verbose();

$curler->writeResponse('someDirectory/Filename');

$curler = new AsyncCurler();

$urls = [
    'https://github.com/',
    'http://pastebin.com/',
    'https://google.com/',
    'http://yahoo.com/'
];

$headers = [
    'Connection'        =>      'keep-alive',
    'Accept'            =>      'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language'   =>      'en-US,en;q=0.5',
    'Content-Type'      =>      'application/x-www-form-urlencoded'
];

$cookieJar = '/home/user/testCookie';

$curler->followRedirects()          // Exactly how it sounds.
    ->headerArray($headers)         // Add an array of headers.
    ->cookieJar($cookieJar)         // Set a location for cookies.
    ->returnText()                  // Don't display response.  Get a text string.
    ->suppressRender()              // This will suppress the html from rendering if it is echoed.
    ->addUrl($urls)                 // Add urls to the multi-request..
    ->addUrl('http://php.net/');    // or add them individually.


$html = $curler->go()->getResponse();

var_dump($html);
 

 [
   "url" => "https://github.com/"
   "cookieJarFile" => "/home/parker/gitCookie"
   "headers" => [
     "Connection" => "keep-alive"
     "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
     "Accept-Language" => "en-US,en;q=0.5"
     "Host" => "github.com"
     "Content-Type" => "application/x-www-form-urlencoded"
   ]
   "postfields" => []
   "poststring" => ""
   "handles" => []
   "options" => [
     "CURLOPT_FOLLOWLOCATION" => true
     "CURLOPT_COOKIEFILE" => "/home/parker/gitCookie"
     "CURLOPT_COOKIEJAR" => "/home/parker/gitCookie"
     "CURLOPT_RETURNTRANSFER" => true
     "CURLOPT_HTTPHEADER" => [
       0 => "Connection: keep-alive"
       1 => "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
       2 => "Accept-Language: en-US,en;q=0.5"
       3 => "Host: github.com"
       4 => "Content-Type: application/x-www-form-urlencoded"
     ]
   ]
   "curl_getinfo" => [
     "url" => "https://github.com/"
     "content_type" => null
     "http_code" => 0
     "header_size" => 0
     "request_size" => 0
     "filetime" => 0
     "ssl_verify_result" => 0
     "redirect_count" => 0
     "total_time" => 0.0
     "namelookup_time" => 0.0
     "connect_time" => 0.0
     "pretransfer_time" => 0.0
     "size_upload" => 0.0
     "size_download" => 0.0
     "speed_download" => 0.0
     "speed_upload" => 0.0
     "download_content_length" => -1.0
     "upload_content_length" => -1.0
     "starttransfer_time" => 0.0
     "redirect_time" => 0.0
     "redirect_url" => ""
     "primary_ip" => ""
     "certinfo" => []
     "primary_port" => 0
     "local_ip" => ""
     "local_port" => 0
   ]
 ]