PHPackages                             cdcchen/gif - 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. cdcchen/gif

ActiveLibrary

cdcchen/gif
===========

http client

1.0.0(8y ago)02BSD-4-ClausePHPPHP &gt;=7.1

Since Oct 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/cdcchen/gif)[ Packagist](https://packagist.org/packages/cdcchen/gif)[ Docs](https://github.com/cdcchen/gif)[ RSS](/packages/cdcchen-gif/feed)WikiDiscussions master Synced 4d ago

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

CURL Http Client
================

[](#curl-http-client)

composer 安装
-----------

[](#composer-安装)

```
composer require cdcchen/curl-client:^1.0.0

```

使用教程
----

[](#使用教程)

### 第一步：实例化`HttpRequest`

[](#第一步实例化httprequest)

```
$request = new HttpRequest();
$request->setUrl('http://www.baidu.com')
```

### 第二步：发起请求

[](#第二步发起请求)

```
$response = $request->send();
```

### 第三步：获取返回相关数据

[](#第三步获取返回相关数据)

返回的`$response`类型为`HttpResponse`。`HttpResponse`会自动根据返回的`Content-Type`解析返回的数据。目前支持以下格式：

- HttpRequest::FORMAT\_JSON
- HttpRequest::FORMAT\_XML
- HttpRequest::FORMAT\_URLENCODED
- HttpRequest::FORMAT\_RAW\_URLENCODED

如果已经明确知道返回数据的格式，也可以显式的指定`$response`的format属性：

```
$response->setFormat(HttpRequest::FORMAT_JSON);
```

然后可以直接通过`$response->getData()`来获取到解析之后的数据。

#### 获取 Status Code

[](#获取-status-code)

```
$response->getStatus()
```

#### 获取原始 body 数据：

[](#获取原始-body-数据)

```
$response->getContent();
```

#### 获取返回的 Headers

[](#获取返回的-headers)

```
$response->hasHeader($name);
$response->getHeader($name);
$response->getHeaders();
```

#### 获取 Cookies

[](#获取-cookies)

```
$response->getCookies();
```

设置超时时间
------

[](#设置超时时间)

```
$request->setConnectTimeout($value, $ms = false);
$request->setTimeout($value, $ms = false);
```

设置 HttpRequest 请求
-----------------

[](#设置-httprequest-请求)

### 设置请求方法

[](#设置请求方法)

```
$request->setMethod('post');
```

### 设置请求参数

[](#设置请求参数)

```
$request->setData(array $data);
```

### 设置post body

[](#设置post-body)

```
$request->setContent($content);
```

### 设置Header

[](#设置header)

```
$request->addHeader($name, $value);
$request->addHeaders($headers);
$request->removeHeader($name);
$request->clearHeaders();
```

### Header shortcut

[](#header-shortcut)

```
$request->setReferrer($referrer = true);
$request->setBasicAuth($username, $password);
$request->setUserPassword($username, $password);
$request->setUserAgent($agent);
$request->setFollowLocation($value = true, $maxRedirects = 5);
$request->setVersion($version);
$request->setAcceptEncoding($value);

```

### 设置Cookies

[](#设置cookies)

```
$request->addCookie($name, $value);
$request->addCookies($cookies);
$request->setCookieFile($file, $jar = null);
```

### 使用SSL

[](#使用ssl)

```
$reqeust->setSSL($peer = false, $host = 2, array $extraOptions = []);
```

### 上传文件

[](#上传文件)

```
$request->addFile($input_name, $file, $mime_type = null, $post_name = null);
$request->addFiles($input_name, array $files, $mime_type = null, $post_name = null);
$request->clearFiles();
```

> $file 可以为文件路径，也可以为CURLFile实例。

### 设置发起请求时body的格式化方式

[](#设置发起请求时body的格式化方式)

```
$request->setFormat($value);
```

`request`会自动根据format的值来格式化`data`

`format`的取值如下：

- HttpRequest::FORMAT\_URLENCODED 默认
- HttpRequest::FORMAT\_RAW\_URLENCODED
- HttpRequest::FORMAT\_JSON
- HttpRequest::FORMAT\_XML

配置 Curl Options
---------------

[](#配置-curl-options)

```
$request->addOption($name, $value);
$request->addOptions(array $options);
$request->removeOptions($options);
$request->clearOptions();
$request->resetOptions($setDefaultOptions = true);
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3133d ago

### Community

Maintainers

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

---

Top Contributors

[![cdcchen](https://avatars.githubusercontent.com/u/748891?v=4)](https://github.com/cdcchen "cdcchen (1 commits)")

---

Tags

gifgif creatorgif extractor

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cdcchen-gif/health.svg)

```
[![Health](https://phpackages.com/badges/cdcchen-gif/health.svg)](https://phpackages.com/packages/cdcchen-gif)
```

###  Alternatives

[tumblr/tumblr

Official Tumblr PHP Client

405416.2k9](/packages/tumblr-tumblr)[intervention/gif

PHP GIF Encoder/Decoder

5520.3M9](/packages/intervention-gif)[sybio/gif-creator

PHP class that creates animated GIF from multiple images

326395.7k14](/packages/sybio-gif-creator)[sybio/gif-frame-extractor

PHP class that separates all the frames (and their duration) of an animated GIF

179417.2k8](/packages/sybio-gif-frame-extractor)[jolicode/gif-exception-bundle

The GhostBuster of your exception page

20596.8k](/packages/jolicode-gif-exception-bundle)[lunakid/anim-gif

PHP class to create an animated GIF from multiple images

90136.3k1](/packages/lunakid-anim-gif)

PHPackages © 2026

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