PHPackages                             qfsx/yii2-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. [HTTP &amp; Networking](/categories/http)
4. /
5. qfsx/yii2-curl

ActiveYii2-extension[HTTP &amp; Networking](/categories/http)

qfsx/yii2-curl
==============

Easy and nice cURL extension with RESTful support for Yii2

1.0.2(3y ago)0221[1 PRs](https://github.com/qfsx/yii2-curl/pulls)MITPHPPHP ^7.0|^8.0

Since Oct 28Pushed 2y agoCompare

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

READMEChangelogDependencies (1)Versions (3)Used By (0)

yii2-curl extension
===================

[](#yii2-curl-extension)

Easy working cURL extension for Yii2, including RESTful support:

- POST
- GET
- HEAD
- PUT
- PATCH
- DELETE
- OPTIONS

Requirements
------------

[](#requirements)

- Yii2
- PHP &gt;=7.0
- ext-curl, ext-json, and php-curl installed

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

[](#installation)

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

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

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your code. The following example shows you how to handling a simple GET Request.

```
use qfsx\yii2\curl\Curl;
$curl = new Curl();

//get http://example.com/
$response = $curl->get('http://example.com/');

if ($curl->errorCode === null) {
   echo $response;
} else {
     // List of curl error codes here https://curl.haxx.se/libcurl/c/libcurl-errors.html
    switch ($curl->errorCode) {

        case 6:
            //host unknown example
            break;
    }
}
```

```
// GET request with GET params
// http://example.com/?key=value&scondKey=secondValue
$curl = new Curl();
$response = $curl->setGetParams([
        'key' => 'value',
        'secondKey' => 'secondValue'
     ])
     ->get('http://example.com/');
```

```
// POST URL form-urlencoded
$curl = new Curl();
$response = $curl->setPostParams([
        'key' => 'value',
        'secondKey' => 'secondValue'
     ])
     ->post('http://example.com/');
```

```
// POST RAW JSON
$curl = new Curl();
$response = $curl->setRawPostData(
     json_encode[
        'key' => 'value',
        'secondKey' => 'secondValue'
     ])
     ->post('http://example.com/');
```

```
// POST RAW JSON and auto decode JSON respawn by setting raw = true.
// This is usefull if you expect an JSON response and want to autoparse it.
$curl = new Curl();
$response = $curl->setRawPostData(
     json_encode[
        'key' => 'value',
        'secondKey' => 'secondValue'
     ])
     ->post('http://example.com/', true);

// JSON decoded response by parsing raw = true in to ->post().
var_dump($response);
```

```
// POST RAW XML
$curl = new Curl();
$response = $curl->setRawPostData('Test')
     ->post('http://example.com/');
```

```
// POST with special headers
$curl = new Curl();
$response = $curl->setPostParams([
        'key' => 'value',
        'secondKey' => 'secondValue'
     ])
     ->setHeaders([
        'Custom-Header' => 'user-b'
     ])
     ->post('http://example.com/');
```

```
// POST JSON with body string & special headers
$curl = new Curl();

$params = [
    'key' => 'value',
    'secondKey' => 'secondValue'
];

$response = $curl->setRequestBody(json_encode($params))
     ->setHeaders([
        'Content-Type' => 'application/json',
        'Content-Length' => strlen(json_encode($params))
     ])
     ->post('http://example.com/');
```

```
// Avanced POST request with curl options & error handling
$curl = new Curl();

$params = [
    'key' => 'value',
    'secondKey' => 'secondValue'
];

$response = $curl->setRequestBody(json_encode($params))
     ->setOption(CURLOPT_ENCODING, 'gzip')
     ->post('http://example.com/');

// List of status codes here http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
switch ($curl->responseCode) {

    case 'timeout':
        //timeout error logic here
        break;

    case 200:
        //success logic here
        break;

    case 404:
        //404 Error logic here
        break;
}

//list response headers
var_dump($curl->responseHeaders);
```

Testing
-------

[](#testing)

- Run codeception tests with `vendor/bin/codecept run` in repository root dir. On windows run `vendor\bin\codecept.bat run`.

##### Release 1.0.2 - Changelog

[](#release-102---changelog)

- PHP 8.0+

##### Release 1.0.1 - Changelog

[](#release-101---changelog)

- Add OPTIONS request

##### Release 1.0 - Changelog

[](#release-10---changelog)

- Official stable release

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.9% 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

Unknown

Total

1

Last Release

1292d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c5f0c9efa79ffff1744a4e9ae3d4ac79be7be4a153d5a58230a0233af13c2e0?d=identicon)[qfsx](/maintainers/qfsx)

---

Top Contributors

[![qfsx](https://avatars.githubusercontent.com/u/63365115?v=4)](https://github.com/qfsx "qfsx (10 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

curlyii2extensionrestful

### Embed Badge

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

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

###  Alternatives

[linslin/yii2-curl

Easy and nice cURL extension with RESTful support for Yii2

1811.5M20](/packages/linslin-yii2-curl)[hiqdev/yii2-hiart

ActiveRecord for API

5951.8k3](/packages/hiqdev-yii2-hiart)[joni-jones/yii2-wschat

Online chat based on web sockets and ratchet php

981.3k](/packages/joni-jones-yii2-wschat)[yiiplus/yii2-websocket

使用yii2封装 websocket 扩展

212.6k](/packages/yiiplus-yii2-websocket)

PHPackages © 2026

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