PHPackages                             nyx-solutions/yii2-nyx-curl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. nyx-solutions/yii2-nyx-curl

ActiveLibrary[Framework](/categories/framework)

nyx-solutions/yii2-nyx-curl
===========================

Yii2 NYX cUrl

5.0.0(3y ago)3861BSD-3-ClausePHPPHP &gt;=8.1.0 &lt;8.2

Since Feb 20Pushed 3y ago2 watchersCompare

[ Source](https://github.com/nyx-solutions/yii2-nyx-curl)[ Packagist](https://packagist.org/packages/nyx-solutions/yii2-nyx-curl)[ RSS](/packages/nyx-solutions-yii2-nyx-curl/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (5)Dependencies (3)Versions (11)Used By (0)

Yii PHP Framework Version 2 / NYX cUrl
======================================

[](#yii-php-framework-version-2--nyx-curl)

NYX cUrl is an object-oriented wrapper of the PHP cURL extension that makes it easy to send HTTP requests and integrate with web APIs. This build targets the Yii Framework version 2 and curretly does not adds any functionality to the main library (PHP Curl Class), but adds the `\nyx\request\helpers\CurlHelper` which extends Yii2 Base URL Helper and implements methods to verify and manage URLs.

This extension uses the PHP Curl Class 7.\* by Zach Borboa. For more details about the PHP Curl Class please refer to [php-curl-class/php-curl-class](https://github.com/php-curl-class/php-curl-class) or [www.phpcurlclass.com](https://www.phpcurlclass.com/).

[![Latest Stable Version](https://camo.githubusercontent.com/a842db92ae0e59b734ae0e1add469d2bc5336b2ca709299e8c9579f244a1cb08/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d6375726c2f762f737461626c65)](https://packagist.org/packages/nyx-solutions/yii2-nyx-curl)[![Total Downloads](https://camo.githubusercontent.com/4f901e412253a3e2ac63bca21568e88a9c7d2bd7ed643e630b573937ea5c7b4b/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d6375726c2f646f776e6c6f616473)](https://packagist.org/packages/nyx-solutions/yii2-nyx-curl)[![Latest Unstable Version](https://camo.githubusercontent.com/1c073fea9311d194d8e3e41b1823df7badc322c71f10def782af3c9ad317f44b/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d6375726c2f762f756e737461626c65)](https://packagist.org/packages/nyx-solutions/yii2-nyx-curl)[![License](https://camo.githubusercontent.com/6dbc0c07d0cfd30ef03bc3fa2776ee344f4bfdeaf2126c6b80b690e14e30d502/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d6375726c2f6c6963656e7365)](https://packagist.org/packages/nyx-solutions/yii2-nyx-curl)[![Monthly Downloads](https://camo.githubusercontent.com/19fd2f8e462b8639498d2ec346d3f9333997504997ea2cacc726558d030948a0/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d6375726c2f642f6d6f6e74686c79)](https://packagist.org/packages/nyx-solutions/yii2-nyx-curl)[![Daily Downloads](https://camo.githubusercontent.com/645820d7afb2a5e683a921168f40cf917a1f3ae7e8decf9562014c81e36d0b03/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d6375726c2f642f6461696c79)](https://packagist.org/packages/nyx-solutions/yii2-nyx-curl)[![composer.lock](https://camo.githubusercontent.com/1977dafdfbf3f612aa124d65ff92b51f2158819a735fe63bd2c4d8827bb5d56e/68747470733a2f2f706f7365722e707567782e6f72672f6e79782d736f6c7574696f6e732f796969322d6e79782d6375726c2f636f6d706f7365726c6f636b)](https://packagist.org/packages/nyx-solutions/yii2-nyx-curl)

### Requirements

[](#requirements)

PHP 5.4+.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist nyx-solutions/yii2-nyx-curl "*"
```

or add

```
"nyx-solutions/yii2-nyx-curl": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

### Basic Example

[](#basic-example)

```
$request = new \nyx\request\Curl();

$request->get('https://www.example.com/');
```

### GET Example

[](#get-example)

```
$request = new \nyx\request\Curl();

$request->get('https://www.example.com/search', ['q' => 'keyword']);
```

### POST Example

[](#post-example)

```
$request = new \nyx\request\Curl();

$request->post('https://www.example.com/login/', ['username' => 'myusername', 'password' => 'mypassword']);
```

### Basic Authentication with Error Handle Example

[](#basic-authentication-with-error-handle-example)

```
$request = new \nyx\request\Curl();

$request->setBasicAuthentication('username', 'password');
$request->setUserAgent('MyUserAgent/0.0.1 (+https://www.example.com/bot.html)');
$request->setReferrer('https://www.example.com/url?url=https%3A%2F%2Fwww.example.com%2F');
$request->setHeader('X-Requested-With', 'XMLHttpRequest');
$request->setCookie('key', 'value');

$request->get('https://www.example.com/');

if ($request->error) {
    echo "Error: {$request->errorCode}: {$request->errorMessage}";
} else {
    echo "Response: \n";

    var_dump($request->response);
}

var_dump($request->requestHeaders);
var_dump($request->responseHeaders);
```

### setOpt method Example

[](#setopt-method-example)

```
$request = new \nyx\request\Curl();

$request->setOpt(CURLOPT_FOLLOWLOCATION, true);

$request->get('https://shortn.example.com/bHbVsP');
```

### PUT Example

[](#put-example)

```
$request = new \nyx\request\Curl();

$request->put('https://api.example.com/user/', ['first_name' => 'Zach', 'last_name' => 'Borboa']);
```

### PATCH Example

[](#patch-example)

```
$request = new \nyx\request\Curl();

$request->patch('https://api.example.com/profile/', ['image' => '@path/to/file.jpg']);
```

```
$request = new \nyx\request\Curl();

$request->patch('https://api.example.com/profile/', ['image' => new CURLFile('path/to/file.jpg')]);
```

### DELETE Example

[](#delete-example)

```
$request = new \nyx\request\Curl();

$request->delete('https://api.example.com/user/', ['id' => '1234']);
```

### Download with GZIP Compression Example

[](#download-with-gzip-compression-example)

```
// Enable gzip compression and download a file.

$request = new \nyx\request\Curl();

$request->setOpt(CURLOPT_ENCODING , 'gzip');

$request->download('https://www.example.com/image.png', '/tmp/myimage.png');
```

```
// Case-insensitive access to headers.
$request = new \nyx\request\Curl();
$request->download('https://www.example.com/image.png', '/tmp/myimage.png');
echo $request->responseHeaders['Content-Type'] . "\n"; // image/png
echo $request->responseHeaders['CoNTeNT-TyPE'] . "\n"; // image/png
```

```
$request->close();
```

### \\nyx\\request\\Curl Available Methods

[](#nyxrequestcurl-available-methods)

```
Curl::__construct($base_url = null)
Curl::__destruct()
Curl::__get($name)
Curl::beforeSend($callback)
Curl::buildPostData($data)
Curl::call()
Curl::close()
Curl::complete($callback)
Curl::delete($url, $query_parameters = array(), $data = array())
Curl::download($url, $mixed_filename)
Curl::error($callback)
Curl::exec($ch = null)
Curl::get($url, $data = array())
Curl::getCookie($key)
Curl::getInfo($opt)
Curl::getOpt($option)
Curl::getResponseCookie($key)
Curl::head($url, $data = array())
Curl::headerCallback($ch, $header)
Curl::options($url, $data = array())
Curl::patch($url, $data = array())
Curl::post($url, $data = array(), $follow_303_with_post = false)
Curl::progress($callback)
Curl::put($url, $data = array())
Curl::removeHeader($key)
Curl::search($url, $data = array())
Curl::setBasicAuthentication($username, $password = '')
Curl::setConnectTimeout($seconds)
Curl::setCookie($key, $value)
Curl::setCookieFile($cookie_file)
Curl::setCookieJar($cookie_jar)
Curl::setCookieString($string)
Curl::setDefaultDecoder($decoder = 'json')
Curl::setDefaultJsonDecoder()
Curl::setDefaultTimeout()
Curl::setDefaultUserAgent()
Curl::setDefaultXmlDecoder()
Curl::setDigestAuthentication($username, $password = '')
Curl::setHeader($key, $value)
Curl::setHeaders($headers)
Curl::setJsonDecoder($function)
Curl::setMaxFilesize($bytes)
Curl::setOpt($option, $value)
Curl::setOpts($options)
Curl::setPort($port)
Curl::setReferer($referer)
Curl::setReferrer($referrer)
Curl::setTimeout($seconds)
Curl::setUrl($url, $data = array())
Curl::setUserAgent($user_agent)
Curl::setXmlDecoder($function)
Curl::success($callback)
Curl::unsetHeader($key)
Curl::verbose($on = true, $output = STDERR)
Curl::array_flatten_multidim($array, $prefix = false)
Curl::is_array_assoc($array)
Curl::is_array_multidim($array)
```

### \\nyx\\request\\MultiCurl Available Methods

[](#nyxrequestmulticurl-available-methods)

```
MultiCurl::__construct($base_url = null)
MultiCurl::__destruct()
MultiCurl::addCurl(Curl $curl)
MultiCurl::addDelete($url, $query_parameters = array(), $data = array())
MultiCurl::addDownload($url, $mixed_filename)
MultiCurl::addGet($url, $data = array())
MultiCurl::addHead($url, $data = array())
MultiCurl::addOptions($url, $data = array())
MultiCurl::addPatch($url, $data = array())
MultiCurl::addPost($url, $data = array(), $follow_303_with_post = false)
MultiCurl::addPut($url, $data = array())
MultiCurl::addSearch($url, $data = array())
MultiCurl::beforeSend($callback)
MultiCurl::close()
MultiCurl::complete($callback)
MultiCurl::error($callback)
MultiCurl::getOpt($option)
MultiCurl::removeHeader($key)
MultiCurl::setBasicAuthentication($username, $password = '')
MultiCurl::setConcurrency($concurrency)
MultiCurl::setConnectTimeout($seconds)
MultiCurl::setCookie($key, $value)
MultiCurl::setCookieFile($cookie_file)
MultiCurl::setCookieJar($cookie_jar)
MultiCurl::setCookieString($string)
MultiCurl::setDigestAuthentication($username, $password = '')
MultiCurl::setHeader($key, $value)
MultiCurl::setHeaders($headers)
MultiCurl::setJsonDecoder($function)
MultiCurl::setOpt($option, $value)
MultiCurl::setOpts($options)
MultiCurl::setPort($port)
MultiCurl::setReferer($referer)
MultiCurl::setReferrer($referrer)
MultiCurl::setTimeout($seconds)
MultiCurl::setUrl($url)
MultiCurl::setUserAgent($user_agent)
MultiCurl::setXmlDecoder($function)
MultiCurl::start()
MultiCurl::success($callback)
MultiCurl::unsetHeader($key)
MultiCurl::verbose($on = true, $output = STDERR)
```

You can find more examples at .

Security Considerations
-----------------------

[](#security-considerations)

### Url may point to system files

[](#url-may-point-to-system-files)

- Don't blindly accept urls from users as they may point to system files. Curl supports many protocols including `FILE`. The following would show the contents of `file:///etc/passwd`.

```
# Attacker.
$ curl https://www.example.com/display_webpage.php?url=file%3A%2F%2F%2Fetc%2Fpasswd
```

```
// display_webpage.php
$url = $_GET['url']; // DANGER!

$request = new \nyx\request\Curl();
$request->get($url);

echo $request->response;
```

Safer:

```
$url = $_GET['url'];

if (!\nyx\request\helpers\CurlHelper::isValidUrl($url)) {
    die('Unsafe url detected.');
}
```

### Url may point to internal urls

[](#url-may-point-to-internal-urls)

- Url may point to internal urls including those behind a firewall (e.g.  or ftp://192.168.0.1/). Use a whitelist to allow certain urls rather than a blacklist.

### Request data may refer to system files

[](#request-data-may-refer-to-system-files)

- Request data prefixed with the `@` character may have special interpretation and read from system files.

```
# Attacker.
$ curl https://www.example.com/upload_photo.php --data "photo=@/etc/passwd"
```

```
// upload_photo.php
$request = new \nyx\request\Curl();

$request->post('http://www.anotherwebsite.com/', ['photo' => $_POST['photo']]); // DANGER!
```

### Unsafe response with redirection enabled

[](#unsafe-response-with-redirection-enabled)

- Requests with redirection enabled may return responses from unexpected sources. Downloading  may redirect and download

```
$request = new \nyx\request\Curl();

$request->setOpt(CURLOPT_FOLLOWLOCATION, true); // DANGER!

$request->download('https://www.example.com/image.png', 'my_image.png');
```

### Keep SSL protections enabled.

[](#keep-ssl-protections-enabled)

- Do not disable SSL protections.

```
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // DANGER!
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // DANGER!
```

**Based on the following document: .**

License
-------

[](#license)

**yii2-nyx-curl** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details.

To find more informations about the **PHP Curl Class** Licence, please refer to [php-curl-class/php-curl-class](https://github.com/php-curl-class/php-curl-class).

[![Yii2](https://camo.githubusercontent.com/d6b0929173e28cc627430d2519ca1853466a70f37395877eaf4820cb3e1e1909/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f77657265645f62792d5969695f4672616d65776f726b2d677265656e2e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/d6b0929173e28cc627430d2519ca1853466a70f37395877eaf4820cb3e1e1909/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f77657265645f62792d5969695f4672616d65776f726b2d677265656e2e7376673f7374796c653d666c6174)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 86.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~254 days

Recently: every ~514 days

Total

10

Last Release

1440d ago

Major Versions

1.0.6 → 2.0.02020-05-02

2.0.0 → 4.0.02022-06-01

4.0.0 → 5.0.02022-06-02

PHP version history (3 changes)1.0.0PHP &gt;=5.4.0

2.0.0PHP &gt;=7.4.0

5.0.0PHP &gt;=8.1.0 &lt;8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/f7c641a4199171cc30bf08b9bf67636a8463acf86813fa259aab131b5bd5a161?d=identicon)[nyx-solutions](/maintainers/nyx-solutions)

---

Top Contributors

[![jsas4coding](https://avatars.githubusercontent.com/u/4156892?v=4)](https://github.com/jsas4coding "jsas4coding (13 commits)")[![brenoherculano](https://avatars.githubusercontent.com/u/90738807?v=4)](https://github.com/brenoherculano "brenoherculano (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

requestphpframeworkcurlyii2extension

### Embed Badge

![Health badge](/badges/nyx-solutions-yii2-nyx-curl/health.svg)

```
[![Health](https://phpackages.com/badges/nyx-solutions-yii2-nyx-curl/health.svg)](https://phpackages.com/packages/nyx-solutions-yii2-nyx-curl)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
