PHPackages                             xionglonghua/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. xionglonghua/yii2-curl

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

xionglonghua/yii2-curl
======================

A curl encapsulation for yii2 framework

0.0.2(7y ago)05091MITPHP

Since Feb 26Pushed 7y ago1 watchersCompare

[ Source](https://github.com/xionglonghua/yii2-curl)[ Packagist](https://packagist.org/packages/xionglonghua/yii2-curl)[ Docs](https://github.com/xionglonghua/yii2-curl)[ RSS](/packages/xionglonghua-yii2-curl/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (3)Used By (1)

CURL Encapsulation for Yii 2
============================

[](#curl-encapsulation-for-yii-2)

This extension provides a curl encapsulation for yii2. you can use it for rapid develop;
这个扩展提供了一个基于yii2的curl封装，通过它你能快速的开发。

For license information check the [LICENSE](LICENSE.md)-file.
在此处可以查看本扩展的[许可](LICENSE.md)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
推荐的方式是通过composer 进行下载安装[composer](http://getcomposer.org/download/)。

Either run
在命令行执行

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

```

or add
或加入

```
"xionglonghua/yii2-curl": "*"

```

to the require-dev section of your `composer.json` file.
到你的`composer.json`文件中的require-dev段。

Usage
-----

[](#usage)

Once the extension is installed, simply modify your application configuration as follows:
一旦你安装了这个插件，你就可以直接在配置文件中加入如下的代码：

Now we will use [baiduApistore](http://apistore.baidu.com) to show how can use it:
现在我们用[百度apistore](http://apistore.baidu.com)来举例说明你如何使用它:

```
return [
    'components' => [
        'baiduApi' => [
            'class' => 'xionglonghua\curl\CurlHttp',
            'host' => 'apis.baidu.com',
            'beforeRequest' => function($params, $curlHttp) {
                //you need put you baidu api key here
                $apikey = 'xxxxxx';
                $curlHttp->setHeader('apikey', $apikey);
                return $params;
            },
            'afterRequest' => function($response, $curlHttp) {
                // you may want process the request here, this is just a example
                $code = curl_getinfo($curlHttp->getCurl(), CURLINFO_HTTP_CODE);
                if($code == 200) {
                    $data = json_decode($response, true);
                    if(empty($data) || empty($data['code'])) {
                        Yii::warning("error!", "curl.baidu");
                    }
                    Yii::info("ok!", "curl.baidu");
                    return $response;
                }
                Yii::error("error", "curl.baidu");
                return $response;
            }
            //'protocol' => 'http',
            //'port' => 80,
            // ...
        ],
    ],
    // ....
];
```

After that, you can use it as follow:
在配置好之后，你可以这么访问它：

```
// you can use this search beijin weather,  http://apistore.baidu.com/apiworks/servicedetail/112.html
$data = Yii::$app->baiduApi
                ->setGet()
                ->httpExec("/apistore/weatherservice/recentweathers", ['cityname' => '北京', 'cityid' => '101010100']);
// you can also use this search the real address of a ip address, http://apistore.baidu.com/apiworks/servicedetail/114.html
$data = Yii::$app->baiduApi
            ->setGet()
            ->httpExec("/apistore/iplookupservice/iplookup", ['ip' => '117.89.35.58']);
// any other apis
```

as you see, once you configed a api, you can use it anywhere, have fun!
如上所见，一旦你配置好了对接的参数和处理，你就能在任何地方很方便的使用它了，祝您使用愉快！

广告
--

[](#广告)

我们是一群热爱技术，追求卓越的极客，我们乐于做一些对整个社会都有作用的事情，我们希望通过我们的努力来推动整个社会的创新，如果你也一样，欢迎加入我们！

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

2

Last Release

2632d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c6bf990248f70507137de9c050513c5e30b2454592f525039d8c67e33bf2090e?d=identicon)[xionglonghua](/maintainers/xionglonghua)

---

Top Contributors

[![xionglonghua](https://avatars.githubusercontent.com/u/13514519?v=4)](https://github.com/xionglonghua "xionglonghua (5 commits)")

---

Tags

curlyii2extension

### Embed Badge

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

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

###  Alternatives

[linslin/yii2-curl

Easy and nice cURL extension with RESTful support for Yii2

1811.5M20](/packages/linslin-yii2-curl)[bryglen/yii2-apns-gcm

Yii 2 Apns and Gcm together

54277.8k1](/packages/bryglen-yii2-apns-gcm)[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)[afinogen89/get-mail

Get Mail from POP3

116.8k](/packages/afinogen89-get-mail)

PHPackages © 2026

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