Download the PHP package hyphun/hypcurl without Composer

On this page you can find all versions of the php package hyphun/hypcurl. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hypcurl

HypCurl

Organised, reusable cURL toolkit for PHP 8.1+. Define each external API once as a small class, then call it from code or the terminal. Retries, timeouts, cookies, proxies, custom headers and logging are handled in one place.

Installation

Quick start

1. Generate your API class

Pass a name to generate more classes, one per external API: make:api Payments, make:api Sms. The namespace and folder are read from your composer.json PSR-4 autoload; with "App\\": "src/" you get App\Api\HypClass in src/Api/. You can override them with --namespace=... --path=....

2. Fill it in

The generated class works immediately: it points at httpbin.org, which echoes requests back. It has three marked sections for you to edit:

Set its URL and token in config/hypcurl/default.env / local.env. The keys use the class name as a prefix:

3. Use it in code

4. Or from the terminal

Without the generator, a class only needs to extend Hyphun\HypCurl\Api\ApiClient and implement options().

Use it directly (no extra class)

You don't have to create an API class. Call HypCurl from any class you already have.

One-off calls with a full URL:

HypCurl::get/post/put/patch/delete/request() share one client, so cookies are kept between calls, like a browser.

A configured client in your existing class. Set the base URL, auth, headers and retries once, then use the client in any method:

Each HypCurl::client() has its own settings, cookies and connection. Every request option shown below (headers, cookies, proxy, uploads, …) works the same way. See examples/direct_usage.php.

Which approach to use: direct use suits a few calls inside an existing class. An API class (make:api) is better when an API is used in many places, or when you want to call it from the terminal.

Configuration

HypCurl works without any setup. It reads HYPCURL_* environment variables and falls back to built-in defaults. To use config files, or to plug in your app's logger, call boot() once at startup:

Priority, highest first: values → environment variables → local.env → {env}.env → default.env → built-in defaults.

Key Default Meaning
HYPCURL_TIMEOUT 30 Total request timeout (s)
HYPCURL_CONNECT_TIMEOUT 10 Connect timeout (s)
HYPCURL_RETRIES 0 Retries on network error, 429, 5xx
HYPCURL_RETRY_DELAY_MS 500 First retry delay, doubles each retry
HYPCURL_VERIFY_SSL true Verify TLS certificate + hostname (false = curl -k)
HYPCURL_CA_BUNDLE Extra CA certificate file (PEM) to trust
HYPCURL_FOLLOW_REDIRECTS true Follow 3xx redirects (curl -L)
HYPCURL_MAX_REDIRECTS 10 Max redirects to follow
HYPCURL_USER_AGENT HypCurl/1.0
HYPCURL_HEADERS Extra headers for every request: X-App: a \| X-Env: dev
HYPCURL_COOKIES true Keep a cookie session per API client
HYPCURL_COOKIE_JAR Cookie file shared between runs
HYPCURL_PROXY http://user:pass@host:3128, socks5h://host:1080, or none
HYPCURL_NO_PROXY localhost,.internal
HYPCURL_LOG_LEVEL INFO DEBUG, INFO, WARN, ERROR, OFF
HYPCURL_DRY_RUN false Log the curl command instead of sending

All keys use the HYPCURL_ prefix on purpose. Under CGI/FPM, incoming request headers become HTTP_* variables ("httpoxy"), so HTTP_* names must never be used for settings.

Logging: in the CLI, logs go to stderr. In web requests (FPM, FrankenPHP, …), HypCurl stays silent unless you pass a logger.

Global settings: set once, used everywhere

Set the proxy, TLS, redirect, timeout and header settings once at startup, so individual requests never repeat them:

These defaults apply to the HypCurl::get()/post()… shortcuts, to HypCurl::client(), and to every API class. Anything more specific still wins, in this order:

per request (->proxy(), ->insecure(), ->withoutRedirects()…) > client / API options() > defaults > *`HYPCURL_` config > built-in**

Headers are merged rather than replaced. Unknown option names throw an error, so a typo like proxyy is caught. You can also change the defaults later with HypCurl::defaults([...]). Call boot() before you create clients: a HypCurl::client() made earlier keeps its settings. Full example: examples/global_settings.php.

Requests

All of these work the same on HypCurl::get(...), on a HypCurl::client(), and inside an API class.

Responses

Errors

Every failure throws a structured exception with a readable message, a machine-readable type, and a hint on how to fix it. All of them extend HttpException:

JSON. Exceptions and responses share one envelope:

Success looks like {"success": true, "status": 200, "data": {...}}.

Without exceptions. trySend() never throws; check the result instead:

A client created with 'throw' => false behaves the same way for every request.

Uncaught errors become JSON. Add this once at startup, and an uncaught HypCurl error becomes a clean JSON response instead of Fatal error: Uncaught ... with a stack trace:

On the web it responds 502 Bad Gateway, or 504 for timeouts, with Content-Type: application/json. In the CLI it prints the JSON and exits with code 1. Other exceptions go to your existing handler unless you pass 'all' => true.

Secrets are hidden everywhere errors and logs appear: passwords in URLs, and token/api_key/password-style query parameters, are shown as ****.

Cookies: chained requests

Across separate CLI runs, use a cookie jar file:

Headers

Scope How
Every API HYPCURL_HEADERS=X-App: my-app \| X-Env: dev
One API 'headers' => [...] in options()
From now on $api->withHeader('X-Tenant', 'acme'), $api->withoutHeader('Accept')
One request ->header(), ->headers(), ->withoutHeader()
CLI -H "X-Trace: 1" (repeatable), --no-header=User-Agent

Header names are matched case-insensitively. Values of Authorization, Cookie, X-Api-Key and similar headers are masked in logs.

Proxy

Set it globally ('defaults' => ['proxy' => ...] or HYPCURL_PROXY), per API ('proxy' => ... in options()), at runtime ($api->withProxy($url)), or per request (->proxy($url), ->withoutProxy()).

SSL / TLS

Certificates and hostnames are verified by default. Options:

Scope Verify on/off Trust a custom CA
Everything 'defaults' => ['verifySsl' => false] or HYPCURL_VERIFY_SSL=false 'defaults' => ['caBundle' => 'ca.pem'] or HYPCURL_CA_BUNDLE
One API / client 'verifySsl' => false in options, $api->withSslVerification(false) 'caBundle' => 'ca.pem'
One request ->insecure() / ->verifySsl(true) n/a
CLI -k / --insecure --cacert=ca.pem

Only turn verification off for local or dev servers with self-signed certificates. For internal services, prefer caBundle, which keeps verification on and trusts your company's CA.

Redirects

3xx redirects are followed by default, up to 10 hops, and only to http/https URLs: a redirect to file:// and similar is blocked.

Scope How
Everything 'defaults' => ['followRedirects' => false, 'maxRedirects' => 5], HYPCURL_FOLLOW_REDIRECTS, HYPCURL_MAX_REDIRECTS
One API / client 'followRedirects' => false, 'maxRedirects' => 3 in options, $api->withRedirects(false)
One request ->withoutRedirects(), ->followRedirects(true, 3)
CLI --no-follow, --max-redirs=3

CLI reference

The demo services httpbin and jsonplaceholder are available until you set 'examples' => false in hypcurl.php.

Long-running processes

Each API client keeps one curl handle open, so connections are reused, and frees it automatically when the process ends. You never need to call curl_close(). In workers and in FrankenPHP or RoadRunner worker mode, call HypCurl::boot() again, or MyApi::reset(), between jobs or requests. Otherwise cookies and runtime headers carry over from one user to the next.

Development

License

MIT. See LICENSE.


All versions of hypcurl with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
ext-curl Version *
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hyphun/hypcurl contains the following files

Loading the files please wait ...