PHP Classes
elePHPant
Icontem

curl Master: Send HTTP requests using the curl extension

Recommend this page to a friend!
  Info   View files Documentation   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-08-27 (26 days ago) RSS 2.0 feedStarStarStarStar 65%Total: 255 This week: 3All time: 7,495 This week: 227Up
Version License PHP version Categories
curlmaster 1.0.23Custom (specified...5HTTP, PHP 5
Description Author

This class can send HTTP requests using the curl extension.

It can take a given URL and sends a HTTP GET, POST, HEAD requests to respective Web server.

For HTTPS URLs it uses a given certification authority file and verifies the server certificate.

The HTTP request response is returned as an array containing response headers, body, and more.

This class caches responses according to response caching headers and caching can be force overridden.

This class caches session cookies.

  Performance   Level  
Name: Peter Kahl <contact>
Classes: 32 packages by
Country: Hong Kong Hong Kong
Age: ???
All time rank: 6854 in Hong Kong Hong Kong
Week rank: 23 Up1 in Hong Kong Hong Kong Up
Innovation award
Innovation award
Nominee: 18x

Details

curlMaster

cURL wrapper with response caching and cookie storage, methods GET, POST, HEAD.

Usage example, method GET:

use peterkahl\curlMaster\curlMaster;

$curlm = new curlMaster;

# Set the cache directory
$curlm->CacheDir = '/var/www/cache';

# If you want to use SSL/TLS, you need to set the location of CA certificate file.
$curlm->ca_file = '/srv/certs/ca-bundle.crt';

# If you need to set User Agent...
$curlm->useragent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0';

/
 * Caching control & Maximum age of forced cache (in seconds).
 *
 * All responses are cached, but when this value is > 0, caching
 * will be forced regardless of the response headers.
 * Forced caching is useful when you expect the same response for each
 * request or when:
 *   -- debugging
 *   -- you cURL an API with request limit
 *
 * @var integer .... value 0 disables forced caching while header-dependent caching is still on
 *                   value >0 enables forced caching and overrides header-dependent caching
 *                   value <0 disables caching altogether (example -1)
 *
 */
$curlm->ForcedCacheMaxAge = 3600;

# The URL you want to cURL (method GET)
$response = $curlm->Request('https://github.com/');

$url        = $response['url'];
$metod      = $response['method'];
$req_data   = $response['req_data'];
$useragent  = $response['useragent'];
$headers    = $response['headers'];
$body       = $response['body'];
$filename   = $response['filename'];
$cookiefile = $response['cookiefile'];
$exectime   = $response['exectime'];
$status     = $response['status'];
$origin     = $response['origin'];

if ($status != '200') {
  throw new Exception('HTTP request failed with status '.$status);
}

var_dump($response);

/*
array(11) {
  ["url"]=>
  string(19) "https://github.com/"
  ["method"]=>
  string(3) "GET"
  ["req_data"]=>
  string(0) ""
  ["useragent"]=>
  string(82) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0"
  ["headers"]=>
  array(22) {
    ["status"]=>
    string(15) "HTTP/1.1 200 OK"
    ["date"]=>
    string(29) "Fri, 14 Jul 2017 09:20:27 GMT"
    ["content-type"]=>
    string(24) "text/html; charset=utf-8"
    ["transfer-encoding"]=>
    string(7) "chunked"
    ["server"]=>
    string(10) "GitHub.com"
    ["status-1"]=>
    string(6) "200 OK"
    ["cache-control"]=>
    string(8) "no-cache"
    ["vary"]=>
    string(6) "X-PJAX"
    ["x-ua-compatible"]=>
    string(16) "IE=Edge,chrome=1"
    ["set-cookie"]=>
    string(277) "_gh_sess=eyJzZXNzaW9uX2lkIjoiMjhjOWU4NzU0ZmEwMWM3NGJlMjBlMjc1ZGNkOWM5MWEiLCJsYXN0X3JlYWRfZnJvbV9yZXBsaWNhcyI6MTUwMDAyNDAyNjkzNSwiX2NzcmZfdG9rZW4iOiJrM05uanNJTHN1dk1xUWc3NHNUYi9LZ2RPMjNrZHJvazkwU1F2VXhHYkdvPSJ9--d0cc7dd9efbce8aaa918b9d632b7b8b6f31f6b2b; path=/; secure; HttpOnly"
    ["x-request-id"]=>
    string(32) "f29e7ea183a2e1a87757c5abd05f6a9a"
    ["x-runtime"]=>
    string(8) "0.177033"
    ["content-security-policy"]=>
    string(770) "default-src 'none'; base-uri 'self'; child-src render.githubusercontent.com; connect-src 'self' uploads.github.com status.github.com collector.githubapp.com api.github.com www.google-analytics.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com wss://live.github.com; font-src assets-cdn.github.com; form-action 'self' github.com gist.github.com; frame-ancestors 'none'; img-src 'self' data: assets-cdn.github.com identicons.github.com collector.githubapp.com github-cloud.s3.amazonaws.com *.githubusercontent.com; media-src 'none'; script-src assets-cdn.github.com; style-src 'unsafe-inline' assets-cdn.github.com"
    ["strict-transport-security"]=>
    string(44) "max-age=31536000; includeSubdomains; preload"
    ["public-key-pins"]=>
    string(447) "max-age=5184000; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho="; pin-sha256="k2v657xBsOVe1PQRwOsHsw3bsGT2VzIqz5K+59sNQws="; pin-sha256="K87oWBWM9UZfyddvDfoxL+8lpNyoUB2ptGtn0fv6G2Q="; pin-sha256="IQBnNBEiFuhj+8x6X8XLgh01V9Ic5/V3IRQLNFFc7v4="; pin-sha256="iie1VXtL7HzAMF+/PVPR9xzT80kQxdZeJ+zduCB3uj0="; pin-sha256="LvRiGEjRqfzurezaWuj8Wie2gyHMrW5Q06LspMnox7A="; includeSubDomains"
    ["x-content-type-options"]=>
    string(7) "nosniff"
    ["x-frame-options"]=>
    string(4) "deny"
    ["x-xss-protection"]=>
    string(13) "1; mode=block"
    ["x-runtime-rack"]=>
    string(8) "0.185461"
    ["content-encoding"]=>
    string(4) "gzip"
    ["vary-2"]=>
    string(15) "Accept-Encoding"
    ["x-github-request-id"]=>
    string(33) "823A:1208D:846845:C90F8D:59688CDA"
  }
  ["body"]=>
  string(54914) "<!DOCTYPE html>
<html lang="en">
  <head>

  ... TRUNCATED

  </body>
</html>"
  ["filename"]=>
  string(58) "/CURL_RESPON-7784acb958509aaf4c6de4d5293f297cf324df86.3600"
  ["exectime"]=>
  string(8) "2.13 sec"
  ["cookiefile"]=>
  string(70) "/srv/cache/CURL_COOKIE-c2208abde9668e8e9815c3690855edd1e63abeac.604800"
  ["status"]=>
  string(3) "200"
  ["origin"]=>
  string(3) "new"
}
*/

Usage example, method POST:

use peterkahl\curlMaster\curlMaster;

$curlm = new curlMaster;

# Set the cache directory
$curlm->CacheDir = '/var/www/cache';

# If you want to use SSL/TLS, you need to set the location of CA certificate file.
$curlm->ca_file = '/srv/certs/ca-bundle.crt';

# If you need to set User Agent...
$curlm->useragent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0';

$curlm->ForcedCacheMaxAge = 3600;

$data = array(
  'user' => 'admin',
  'pwd'  => 'oracle',
);

# The URL you want to cURL
$response = $curlm->Request('https://whatever.anything/login', 'POST', $data);

Cache Purging:

Although the cache is being purged automatically, you may want to purge the cache yourself (e.g. as crontab job).

use peterkahl\curlMaster\curlMaster;

$curlm = new curlMaster;

# Set the cache directory
$curlm->CacheDir = '/var/www/cache';

$curlm->PurgeCache();
  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file curlMaster.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:255
This week:3
All time:7,495
This week:227Up
User Ratings User Comments (1)
 All time
Utility:93%StarStarStarStarStar
Consistency:93%StarStarStarStarStar
Documentation:93%StarStarStarStarStar
Examples:-
Tests:-
Videos:-
Overall:65%StarStarStarStar
Rank:735
 
nice
5 months ago (muabshir)
70%StarStarStarStar