Download the PHP package codezero/curl without Composer

On this page you can find all versions of the php package codezero/curl. 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 curl

Simple cURL Wrapper

[GitHub release]() [License]() Build Status Scrutinizer Total Downloads

This package wraps most of the cURL functions in a dedicated Curl class, making it feel more object oriented and a little easier to use.

More importantly, the Request class provides some friendly methods that will set the most commonly used cURL options for you, so you don't have to memorize these.

This is a simple cURL wrapper. Some features are not supported (yet):

Installation

You can download this package, or install it through Composer:

"require": {
    "codezero/curl": "1.*"
}

Usage

Send requests, the easy way!

Create a Request instance:

$request = new \CodeZero\Curl\Request();

You can now use this for all of your requests. You don't need to create a new instance for every request.

Configure the request:

$url = 'http://my.site/api';
$data = ['do' => 'something', 'with' => 'this']; //=> Optional
$headers = ['Some Header' => 'Some Value']; //=> Optional

If you want you can set custom cURL options, before sending the request:

$request->setOption(CURLOPT_USERAGENT, 'My User Agent');

... or unset one:

$request->unsetOption(CURLOPT_USERAGENT);

NOTE: Only the URL, data and headers option, and a few options that are required for the given request method will be reset automatically on every request. Custom options will remain set until you unset them. An overview of all cURL options can be found here: http://php.net/manual/en/function.curl-setopt.php

Send the request: (one of the following)

$response = $request->get($url, $data, $headers);
$response = $request->post($url, $data, $headers);
$response = $request->put($url, $data, $headers);
$response = $request->patch($url, $data, $headers);
$response = $request->delete($url, $data, $headers);

All of these methods will return an instance of the CodeZero\Curl\Response class.

Get the response body

$body = $response->getBody();

Get additional request info

Fetch an array with all info:

$info = $response->info()->getList();

Fetch specific information:

$httpCode = $response->info()->getHttpCode(); //=> "200"
$responseType = $response->info()->getResponseType(); //=> "application/json"
$responseCharset = $response->info()->getResponseCharset(); //=> "UTF-8" 

TIP: For an overview of all the available info, take a look at the CodeZero\Curl\ResponseInfo class or refer to http://php.net/manual/en/function.curl-getinfo.php

Exceptions

cURL issues

A CodeZero\Curl\CurlException will be thrown, if there was a problem initializing cURL. This will probably be the case if the cURL extension is not loaded by PHP, or if there is some other local server issue.

Request issues

A CodeZero\Curl\RequestException will be thrown, if cURL was unable to execute the request. This might be the case if your request is not properly configured (unsupported protocol, etc.). Find more information about these kind of errors on http://curl.haxx.se/libcurl/c/libcurl-errors.html

Response issues

HTTP response errors >= 400 will not throw an exception, unless you set the CURLOPT_FAILONERROR cURL option to true. If you do, these errors will also throw a CodeZero\Curl\RequestException, with the proper error message.

Another way to handle HTTP errors is to check the $httpCode value:

if ($httpCode >= 400)
{
    // Handle error...
    // or throw your own exception...
}

Curl Class

You can also use the Curl class instead of the Request class. The difference is that you will need to provide all of the cURL options yourself and you will just get the raw response back instead of the Response object.

Quick example:

$options = [
    CURLOPT_URL => 'http://my.site/api',
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPGET => true,
    CURLOPT_RETURNTRANSFER => true
];

$curl = new \CodeZero\Curl\Curl();

// Send & get results
$responseBody = $curl->sendRequest($options); //=> Returns the actual output
$info = $curl->getRequestInfo(); //=> Returns info array

// Get errors
$error = $curl->getError(); //=> For PHP < 5.5.0 this is the same as $curl->getErrorDescription()
$errorCode = $curl->getErrorCode();
$errorDescription = $curl->getErrorDescription();

// Close cURL resource
$curl->close();

Options are not reset automatically after each request. If you need to reset them, you can either run $curl->close() to force a new cURL resource to be initialized at the next request, or you can call $curl->reset().

Long example:

The following will do the exact same thing as the previous example:

$options = [
    CURLOPT_URL => 'http://my.site/api',
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPGET => true,
    CURLOPT_RETURNTRANSFER => true
];

$curl = new \CodeZero\Curl\Curl();

// Setup & send
$curl->initialize();
$curl->setOptions($options);
$curl->sendRequest();

// Get results
$responseBody = $curl->getResponse(); //=> Returns the actual output
$info = $curl->getRequestInfo(); //=> Returns info array

// Get errors
$error = $curl->getError();//=> For PHP < 5.5.0 this is the same as $curl->getErrorDescription()
$errorCode = $curl->getErrorCode();
$errorDescription = $curl->getErrorDescription();

// Close cURL resource
$curl->close();

Error handling:

The Curl class will only throw a CodeZero\Curl\CurlException, when there is some cURL initialization issue. You will need to check the error code to determine if the request had any problems:

if ($errorCode > 0)
{
    // Do something...
}

Testing

$ vendor/bin/phpspec run

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.


Analytics


All versions of curl with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
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 codezero/curl contains the following files

Loading the files please wait ....