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

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

maxwen/yii2-curl
================

A base curl wrapper for Yii2 Framework

1.0(10y ago)811.1k↓100%5MITPHP

Since Jan 8Pushed 9y agoCompare

[ Source](https://github.com/max-wen/yii2-curl)[ Packagist](https://packagist.org/packages/maxwen/yii2-curl)[ RSS](/packages/maxwen-yii2-curl/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Yii-curl
========

[](#yii-curl)

Forked from [shuber/curl](https://github.com/shuber/curl), A base curl wrapper for Yii2 Framework

Installation via Composer
-------------------------

[](#installation-via-composer)

`composer require maxwen/yii2-curl`

Usage
-----

[](#usage)

### Performing a Request

[](#performing-a-request)

The Curl object supports 5 types of requests: HEAD, GET, POST, PUT, and DELETE. You must specify a url to request and optionally specify an associative array or string of variables to send along with it.

```
// set options
$curl = new \maxwen\yii\curl\Curl();
$curlOptions = [
		// 'CURLOPT_SSL_VERIFYHOST'	=> true,
		'CURLOPT_SSL_VERIFYPEER'	=> false,
		'CURLOPT_RETURNTRANSFER' 	=> true,
		'CURLOPT_TIMEOUT' 			=> 30,
	];
$curl->options = $curlOptions;
// send requests
$response = $curl->head($url, $vars = array());
$response = $curl->get($url, $vars = array()); # The Curl object will append the array of $vars to the $url as a query string
$response = $curl->post($url, $vars = array());
$response = $curl->put($url, $vars = array());
$response = $curl->delete($url, $vars = array());

```

To use a custom request methods, you can call the `request` method:

```
$response = $curl->request('YOUR_CUSTOM_REQUEST_TYPE', $url, $vars = array());

```

All of the built in request methods like `put` and `get` simply wrap the `request` method. For example, the `post` method is implemented like:

```
function post($url, $vars = array()) {
    return $this->request('POST', $url, $vars);
}

```

Examples:

```
$response = $curl->get('google.com?q=test');

# The Curl object will append '&some_variable=some_value' to the url
$response = $curl->get('google.com?q=test', array('some_variable' => 'some_value'));

$response = $curl->post('test.com/posts', array('title' => 'Test', 'body' => 'This is a test'));

```

All requests return a CurlResponse object (see below) or false if an error occurred. You can access the error string with the `$curl->error()` method.

### The CurlResponse Object

[](#the-curlresponse-object)

A normal CURL request will return the headers and the body in one response string. This class parses the two and places them into separate properties.

For example

```
$response = $curl->get('google.com');
echo $response->body; # A string containing everything in the response except for the headers
print_r($response->headers); # An associative array containing the response headers

```

Which would display something like

```

Google.com

Some more html...

Array
(
    [Http-Version] => 1.0
    [Status-Code] => 200
    [Status] => 200 OK
    [Cache-Control] => private
    [Content-Type] => text/html; charset=ISO-8859-1
    [Date] => Wed, 07 May 2008 21:43:48 GMT
    [Server] => gws
    [Connection] => close
)

```

The CurlResponse class defines the magic [\_\_toString()](http://php.net/__toString) method which will return the response body, so `echo $response` is the same as `echo $response->body`

### Cookie Sessions

[](#cookie-sessions)

By default, cookies will be stored in a file called `curl_cookie.txt`. You can change this file's name by setting it like this

```
$curl->cookie_file = 'some_other_filename';

```

This allows you to maintain a session across requests

### Basic Configuration Options

[](#basic-configuration-options)

You can easily set the referer or user-agent

```
$curl->referer = 'http://google.com';
$curl->user_agent = 'some user agent string';

```

You may even set these headers manually if you wish (see below)

### Setting Custom Headers

[](#setting-custom-headers)

You can set custom headers to send with the request

```
$curl->headers['Host'] = 12.345.678.90;
$curl->headers['Some-Custom-Header'] = 'Some Custom Value';

```

### Setting Custom CURL request options

[](#setting-custom-curl-request-options)

By default, the `Curl` object will follow redirects. You can disable this by setting:

```
$curl->follow_redirects = false;

```

You can set/override many different options for CURL requests (see the [curl\_setopt documentation](http://php.net/curl_setopt) for a list of them)

```
# any of these will work
$curl->options['AUTOREFERER'] = true;
$curl->options['autoreferer'] = true;
$curl->options['CURLOPT_AUTOREFERER'] = true;
$curl->options['curlopt_autoreferer'] = true;

```

###  Health Score

35

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

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

3726d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dea29ab3f737decc3534de372cc6bf5beb19843ae09802480c77307fed7d3117?d=identicon)[max.wen](/maintainers/max.wen)

---

Top Contributors

[![shuber](https://avatars.githubusercontent.com/u/2419?v=4)](https://github.com/shuber "shuber (14 commits)")[![weppos](https://avatars.githubusercontent.com/u/5387?v=4)](https://github.com/weppos "weppos (7 commits)")[![imaxwen](https://avatars.githubusercontent.com/u/2849142?v=4)](https://github.com/imaxwen "imaxwen (3 commits)")[![anas-mattar](https://avatars.githubusercontent.com/u/11560142?v=4)](https://github.com/anas-mattar "anas-mattar (1 commits)")[![max-wen](https://avatars.githubusercontent.com/u/116544153?v=4)](https://github.com/max-wen "max-wen (1 commits)")

---

Tags

curlyii2extensionrestful

### Embed Badge

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

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

###  Alternatives

[linslin/yii2-curl

Easy and nice cURL extension with RESTful support for Yii2

1811.4M18](/packages/linslin-yii2-curl)[hiqdev/yii2-hiart

ActiveRecord for API

5951.5k3](/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)
