curl Master: Send HTTP requests using the curl extension

Recommend this page to a friend!
  Info   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-09-23 (2 hours ago) RSS 2.0 feedStarStarStarStar 65%Total: 514 This week: 3All time: 5,672 This week: 88Up
Version License PHP version Categories
curlmaster 5.25Custom (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. Cached responses may be explicitly removed. The class looks at the HTTP response ETag headers to determine how to locate the cached responses.

The class also caches session cooky values.

Picture of Peter Kahl
  Performance   Level  
Name: Peter Kahl <contact>
Classes: 37 packages by
Country: United Kingdom
Age: ???
All time rank: 45822 in United Kingdom
Week rank: 8 Up1 in United Kingdom Up
Innovation award
Innovation award
Nominee: 23x

Winner: 2x

Details

curlMaster

Downloads License If this project has business value for you then don't hesitate to support me with a small donation.

Wrapper for the cURL extension with compressed response caching, ETAG support, cookie storage, request methods GET, POST, HEAD.

Usage example, method GET:

use peterkahl\curlMaster\curlMaster;

$curlm = new curlMaster;

$curlm->CacheDir = '/srv/cache';

$curlm->ca_file = '/srv/cert-ca/cacert.pem';

$curlm->ForcedCacheMaxAge = 3600;

$curlm->headers = array('accept: text/html');

// Method GET is default.
$response = $curlm->Request('https://github.com/');

/*
The resulting response is an array, which in a JSON format (from the cache file) is:

{
    "body": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\">\n
    ... [truncated]
    <\/div>\n<\/div>\n\n\n  <\/body>\n<\/html>",
    "cookiefile": "\/srv\/cache\/curlmaster_cookie_github.com.cookie",
    "details": [
        "*   Trying 140.82.121.4:443...",
        "* TCP_NODELAY set",
        "* Connected to github.com (140.82.121.4) port 443 (#0)",
        "* ALPN, offering h2",
        "* ALPN, offering http\/1.1",
        "* successfully set certificate verify locations:",
        "*   CAfile: \/srv\/cert-ca\/cacert.pem",
        "  CApath: \/etc\/ssl\/certs",
        "* SSL connection using TLSv1.3 \/ TLS_AES_128_GCM_SHA256",
        "* ALPN, server accepted to use http\/1.1",
        "* Server certificate:",
        "*  subject: C=US; ST=California; L=San Francisco; O=GitHub, Inc.; CN=github.com",
        "*  start date: May  5 00:00:00 2020 GMT",
        "*  expire date: May 10 12:00:00 2022 GMT",
        "*  subjectAltName: host \"github.com\" matched cert's \"github.com\"",
        "*  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA",
        "*  SSL certificate verify ok.",
        "> GET \/ HTTP\/1.1",
        "Host: github.com",
        "User-Agent: Mozilla\/5.0 (curlMaster\/6.0; +https:\/\/github.com\/peterkahl\/curl-master)",
        "Accept-Encoding: deflate, gzip, br",
        "Cookie: logged_in=no; _gh_sess=E0BFpimS4u5rAthDSCNKhtPf08YyTh2c5GlyrQ4HirYFEnvVDkX%2ByTUTEXj4xVIOJrfYobWv1Ho0%2Bf%2F%2BIUbl%2FRUo3QvmVztQJpnPELgTng%2FCt%2BLF6IS7m6TvbZ56Bc15D21vrKj567zS4PV6UdCXES9FG0t8mn4Glw8G9q0b32y8jEEsjV99SVXHwiIAe43oGfUiazufzqpkaz54ViqMyyku1N%2B8rPgg%2BxzTB5UY8eZns01qdRbANj95m7H4hZ7hdg5475m4BK1uO3PvxHXMbQ%3D%3D--RVag5qxSZPoIcdP6--jpdhd7joTVYhpGOBwWbKBw%3D%3D; _octo=GH1.1.274421626.1599980343",
        "accept: text\/html",
        "",
        "* old SSL session ID is stale, removing",
        "* Mark bundle as not supporting multiuse",
        "< HTTP\/1.1 200 OK",
        "< date: Sun, 13 Sep 2020 07:03:22 GMT",
        "< content-type: text\/html; charset=utf-8",
        "< server: GitHub.com",
        "< status: 200 OK",
        "< vary: X-PJAX, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding",
        "< etag: W\/\"476dc7855ad9e75e6211de16f18d0d7b\"",
        "< cache-control: max-age=0, private, must-revalidate",
        "< strict-transport-security: max-age=31536000; includeSubdomains; preload",
        "< x-frame-options: deny",
        "< x-content-type-options: nosniff",
        "< x-xss-protection: 1; mode=block",
        "< referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin",
        "< expect-ct: max-age=2592000, report-uri=\"https:\/\/api.github.com\/_private\/browser\/errors\"",
        "< content-security-policy: default-src 'none'; base-uri 'self'; block-all-mixed-content; connect-src 'self' uploads.github.com www.githubstatus.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 cdn.optimizely.com logx.optimizely.com\/v1\/events wss:\/\/alive.github.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com; frame-ancestors 'none'; frame-src render.githubusercontent.com; img-src 'self' data: github.githubassets.com identicons.github.com collector.githubapp.com github-cloud.s3.amazonaws.com *.githubusercontent.com customer-stories-feed.github.com spotlights-feed.github.com; manifest-src 'self'; media-src 'none'; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; worker-src github.com\/socket-worker.js gist.github.com\/socket-worker.js",
        "< Content-Encoding: gzip",
        "< Accept-Ranges: bytes",
        "< Transfer-Encoding: chunked",
        "< X-GitHub-Request-Id: 09A4:10571:154A092:2010D17:5F5DC43A",
        "< ",
        "* Closing connection 0",
        ""
    ],
    "error": "CURLE_OK",
    "error_num": 0,
    "exectime": "0.291508",
    "filename": "\/srv\/cache\/curlmaster_response_29198017ee6b848eacb04d27a41f55.json",
    "timestamp": 1599980602,
    "cachingtime": 3600,
    "etag": "W\/\"476dc7855ad9e75e6211de16f18d0d7b\"",
    "headers": {
        "status": "HTTP\/1.1 200 OK",
        "date": "Sun, 13 Sep 2020 07:03:22 GMT",
        "content-type": "text\/html; charset=utf-8",
        "server": "GitHub.com",
        "status-1": "200 OK",
        "vary": "X-PJAX, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding",
        "etag": "W\/\"476dc7855ad9e75e6211de16f18d0d7b\"",
        "cache-control": "max-age=0, private, must-revalidate",
        "strict-transport-security": "max-age=31536000; includeSubdomains; preload",
        "x-frame-options": "deny",
        "x-content-type-options": "nosniff",
        "x-xss-protection": "1; mode=block",
        "referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
        "expect-ct": "max-age=2592000, report-uri=\"https:\/\/api.github.com\/_private\/browser\/errors\"",
        "content-security-policy": "default-src 'none'; base-uri 'self'; block-all-mixed-content; connect-src 'self' uploads.github.com www.githubstatus.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 cdn.optimizely.com logx.optimizely.com\/v1\/events wss:\/\/alive.github.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com; frame-ancestors 'none'; frame-src render.githubusercontent.com; img-src 'self' data: github.githubassets.com identicons.github.com collector.githubapp.com github-cloud.s3.amazonaws.com *.githubusercontent.com customer-stories-feed.github.com spotlights-feed.github.com; manifest-src 'self'; media-src 'none'; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; worker-src github.com\/socket-worker.js gist.github.com\/socket-worker.js",
        "content-encoding": "gzip",
        "accept-ranges": "bytes",
        "transfer-encoding": "chunked",
        "x-github-request-id": "09A4:10571:154A092:2010D17:5F5DC43A"
    },
    "method": "GET",
    "origin": "new",
    "pkeypin": "",
    "req_data": "",
    "status": "200",
    "url": "https:\/\/github.com\/",
    "useragent": "Mozilla\/5.0 (curlMaster\/6.0; +https:\/\/github.com\/peterkahl\/curl-master)",
    "version": "6.0"
}
*/

Usage example, method POST:

use peterkahl\curlMaster\curlMaster;

$curlm->CacheDir = '/srv/cache';

$curlm->ca_file = '/srv/cert-ca/cacert.pem';

$curlm->ForcedCacheMaxAge = 3600;

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

$response = $curlm->Request('https://whatever.anything/login', 'POST', $post_data);

Usage example, method HEAD:

use peterkahl\curlMaster\curlMaster;

$curlm->CacheDir = '/srv/cache';

$curlm->ca_file = '/srv/cert-ca/cacert.pem';

$curlm->ForcedCacheMaxAge = 3600;

$curlm->headers = array('accept: text/html');

$response = $curlm->Request('https://github.com/', 'HEAD');

/*
The resulting response is an array, which in a JSON format (from the cache file) is:

{
    "body": "",
    "cookiefile": "\/srv\/cache\/curlmaster_cookie_github.com.cookie",
    "details": [
        "*   Trying 140.82.121.3:443...",
        "* TCP_NODELAY set",
        "* Connected to github.com (140.82.121.3) port 443 (#0)",
        "* ALPN, offering h2",
        "* ALPN, offering http\/1.1",
        "* successfully set certificate verify locations:",
        "*   CAfile: \/srv\/cert-ca\/cacert.pem",
        "  CApath: \/etc\/ssl\/certs",
        "* SSL connection using TLSv1.3 \/ TLS_AES_128_GCM_SHA256",
        "* ALPN, server accepted to use http\/1.1",
        "* Server certificate:",
        "*  subject: C=US; ST=California; L=San Francisco; O=GitHub, Inc.; CN=github.com",
        "*  start date: May  5 00:00:00 2020 GMT",
        "*  expire date: May 10 12:00:00 2022 GMT",
        "*  subjectAltName: host \"github.com\" matched cert's \"github.com\"",
        "*  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA",
        "*  SSL certificate verify ok.",
        "> HEAD \/ HTTP\/1.1",
        "Host: github.com",
        "User-Agent: Mozilla\/5.0 (curlMaster\/6.0; +https:\/\/github.com\/peterkahl\/curl-master)",
        "Cookie: logged_in=no; _gh_sess=E0BFpimS4u5rAthDSCNKhtPf08YyTh2c5GlyrQ4HirYFEnvVDkX%2ByTUTEXj4xVIOJrfYobWv1Ho0%2Bf%2F%2BIUbl%2FRUo3QvmVztQJpnPELgTng%2FCt%2BLF6IS7m6TvbZ56Bc15D21vrKj567zS4PV6UdCXES9FG0t8mn4Glw8G9q0b32y8jEEsjV99SVXHwiIAe43oGfUiazufzqpkaz54ViqMyyku1N%2B8rPgg%2BxzTB5UY8eZns01qdRbANj95m7H4hZ7hdg5475m4BK1uO3PvxHXMbQ%3D%3D--RVag5qxSZPoIcdP6--jpdhd7joTVYhpGOBwWbKBw%3D%3D; _octo=GH1.1.274421626.1599980343",
        "accept: text\/html",
        "",
        "* old SSL session ID is stale, removing",
        "* Mark bundle as not supporting multiuse",
        "< HTTP\/1.1 200 OK",
        "< date: Sun, 13 Sep 2020 07:13:24 GMT",
        "< content-type: text\/html; charset=utf-8",
        "< server: GitHub.com",
        "< status: 200 OK",
        "< vary: X-PJAX, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding",
        "< etag: W\/\"c02e246aa3d62c850e0133623283435f\"",
        "< cache-control: max-age=0, private, must-revalidate",
        "< strict-transport-security: max-age=31536000; includeSubdomains; preload",
        "< x-frame-options: deny",
        "< x-content-type-options: nosniff",
        "< x-xss-protection: 1; mode=block",
        "< referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin",
        "< expect-ct: max-age=2592000, report-uri=\"https:\/\/api.github.com\/_private\/browser\/errors\"",
        "< content-security-policy: default-src 'none'; base-uri 'self'; block-all-mixed-content; connect-src 'self' uploads.github.com www.githubstatus.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 cdn.optimizely.com logx.optimizely.com\/v1\/events wss:\/\/alive.github.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com; frame-ancestors 'none'; frame-src render.githubusercontent.com; img-src 'self' data: github.githubassets.com identicons.github.com collector.githubapp.com github-cloud.s3.amazonaws.com *.githubusercontent.com customer-stories-feed.github.com spotlights-feed.github.com; manifest-src 'self'; media-src 'none'; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; worker-src github.com\/socket-worker.js gist.github.com\/socket-worker.js",
        "< Accept-Ranges: bytes",
        "< X-GitHub-Request-Id: FC96:2C59:36E85E0:5305817:5F5DC694",
        "< ",
        "* Closing connection 0",
        ""
    ],
    "error": "CURLE_OK",
    "error_num": 0,
    "exectime": "0.260373",
    "filename": "\/srv\/cache\/curlmaster_response_7a47e96bf60222283e9806639e31ff.json",
    "timestamp": 1599981204,
    "cachingtime": 3600,
    "etag": "W\/\"c02e246aa3d62c850e0133623283435f\"",
    "headers": {
        "status": "HTTP\/1.1 200 OK",
        "date": "Sun, 13 Sep 2020 07:13:24 GMT",
        "content-type": "text\/html; charset=utf-8",
        "server": "GitHub.com",
        "status-1": "200 OK",
        "vary": "X-PJAX, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding",
        "etag": "W\/\"c02e246aa3d62c850e0133623283435f\"",
        "cache-control": "max-age=0, private, must-revalidate",
        "strict-transport-security": "max-age=31536000; includeSubdomains; preload",
        "x-frame-options": "deny",
        "x-content-type-options": "nosniff",
        "x-xss-protection": "1; mode=block",
        "referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
        "expect-ct": "max-age=2592000, report-uri=\"https:\/\/api.github.com\/_private\/browser\/errors\"",
        "content-security-policy": "default-src 'none'; base-uri 'self'; block-all-mixed-content; connect-src 'self' uploads.github.com www.githubstatus.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 cdn.optimizely.com logx.optimizely.com\/v1\/events wss:\/\/alive.github.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com; frame-ancestors 'none'; frame-src render.githubusercontent.com; img-src 'self' data: github.githubassets.com identicons.github.com collector.githubapp.com github-cloud.s3.amazonaws.com *.githubusercontent.com customer-stories-feed.github.com spotlights-feed.github.com; manifest-src 'self'; media-src 'none'; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; worker-src github.com\/socket-worker.js gist.github.com\/socket-worker.js",
        "accept-ranges": "bytes",
        "x-github-request-id": "FC96:2C59:36E85E0:5305817:5F5DC694"
    },
    "method": "HEAD",
    "origin": "new",
    "pkeypin": "",
    "req_data": "",
    "status": "200",
    "url": "https:\/\/github.com\/",
    "useragent": "Mozilla\/5.0 (curlMaster\/6.0; +https:\/\/github.com\/peterkahl\/curl-master)",
    "version": "6.0"
}
*/

Cache Purging:

Although the cache can be purged automatically on each request (GET, POST, HEAD), better alternative is to purge the cache yourself, e.g. as crontab job using the available method PurgeCache().

use peterkahl\curlMaster\curlMaster;

$curlm = new curlMaster;

$curlm->CacheDir = '/srv/cache';

$curlm->PurgeCache();
  Files folder image Files  
File Role Description
Files folder imagesrc (2 files)
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
  Plain text file ErrorCode.php Class Class source

 Version Control Reuses Unique User Downloads Download Rankings  
 100%1
Total:514
This week:3
All time:5,672
This week:88Up
User Ratings User Comments (1)
 All time
Utility:93%StarStarStarStarStar
Consistency:93%StarStarStarStarStar
Documentation:93%StarStarStarStarStar
Examples:-
Tests:-
Videos:-
Overall:65%StarStarStarStar
Rank:783
 
nice
3 years ago (muabshir)
70%StarStarStarStar
 

For more information send a message to info at phpclasses dot org.