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

ActiveLibrary[HTTP &amp; Networking](/categories/http)

jinxing/curl
============

Curl

16PHP

Since Oct 3Pushed 4y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Curl
====

[](#curl)

只包含一个`Curl`处理类，不依赖其他库

安装
--

[](#安装)

使用composer安装

```
composer require jinxing/curl
```

使用说明
----

[](#使用说明)

### `Curl` 类的使用

[](#curl-类的使用)

#### 1. 发送`get`请求

[](#1-发送get请求)

```
$curl = new Curl();
$curl->get('http://localhost/', ['username' => 'test']);
$response = $curl->getBody();
```

#### 2. 发送`post`请求

[](#2-发送post请求)

```
$curl = new Curl();
$curl->post('http://localhost/', ['username' => 'test']);
$response = $curl->getBody();
```

#### 3. 重试

[](#3-重试)

> 第三个参数设置间隔时间、以毫秒计算、默认为0

##### 1. 当存在curl错误时候，重试2次, 隔1秒重试1次

[](#1-当存在curl错误时候重试2次-隔1秒重试1次)

```
$curl = new Curl();
$curl->get('http://localhost/', ['username' => 'test'])->retry(2, false, 1000);
$response = $curl->getBody();
```

##### 2. 当存在curl错误、或者响应为空的时候，重试2次, 隔1秒重试1次

[](#2-当存在curl错误或者响应为空的时候重试2次-隔1秒重试1次)

```
$curl = new Curl();
$curl->get('http://localhost/', ['username' => 'test'])->retry(2, true, 1000);
$response = $curl->getBody();
```

##### 3. 指定条件进行重试

[](#3-指定条件进行重试)

当存在错误的时候重试2次

```
$curl = new Curl();
$curl->get('http://localhost/', ['username' => 'test'])->whenRetry(2, function ($ch) {
    // 存在错误、重试
    return $ch->getError();
});
$response = $curl->getBody();
```

##### 4. 不需要暂停等待(没有间隔时间)

[](#4-不需要暂停等待没有间隔时间)

```
$response = (new Curl())->get('http://localhost')->retry(2)->getBody();
```

#### 4. 初始化设置属性

[](#4-初始化设置属性)

初始化设置属性

```
$curl = new Curl([
    'timeout' => 30,    // 设置超时时间
    'isJson'  => true,  // 发送json请求
    'isAjax'  => true,  // ajax 请求
    'headers' => ['Content-type: text/html'], // 设置http header 信息
    // 其他
    'referer'     => 'username:username', // 在HTTP请求头中"Referer: "的内容。
    'sslVerify'   => true,                // 使用ssl证书
    'sslCertFile' => './index',           // 一个包含 PEM 格式证书的文件名
    'sslKeyFile'  => './index',           // 包含 SSL 私钥的文件名

    // 默认curl options 配置
    'options' => [
         CURLOPT_USERAGENT      => 'Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1)',   // 用户访问代理 User-Agent
         CURLOPT_HEADER         => 0,
         CURLOPT_FOLLOWLOCATION => 0, // 跟踪301
         CURLOPT_RETURNTRANSFER => 1, // 返回结果
         CURLOPT_IPRESOLVE      => CURL_IPRESOLVE_V4, // 默认使用IPV4
    ],

    // 其他curl options配置，优先级最高
    'curlOptions' => [
        CURLOPT_TIMEOUT => 50,
    ],
]);
```

使用链式调用

```
$curl = new Curl();
$curl->setTimeout(30)
->setIsJson(true)
->setIsAjax(true)
->setHeaders('Content-type: text/html') // 允许传递数组 setHeaders(['X-Requested-With: XMLHttpRequest', 'X-Prototype-Version: 1.5.0'])
->setReferer('username:username')
->setSslVerify(true)
->setSslCertFile('./index')
->setSslKeyFile('./index')
->setOptions(CURLOPT_TIMEOUT, 50); // 允许传递数组 setOptions([CURLOPT_TIMEOUT => 50])
```

#### Curl 其他方法

[](#curl-其他方法)

方法名称返回值方法说明`delete($url)``Curl`发送delete请求`put($url, $data)``Curl`发送put请求`request($url, $method = 'GET', $data = '')``Curl`发送请求`reset()``Curl`重置Curl类`getBody()``mixed`获取请求响应结果`getError()``int`获取curl错误码`getErrorInfo()``string`获取curl错误信息`getInfo()``string`获取`curl_getinfo`返回信息`getStatusCode()``string`获取请求状态码`getRequestTime()``string`获取请求时间`toArray()``array`curl类请求相关信息数组> 所有私有属性，都可以通过get + 属性名称 方法获取例如： getIsAjax()、getIsJson()、getOptions() 等等

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a622f6dcae0baf206ab50e361b5860394855eda8c05f8818735f5f379318ae57?d=identicon)[jinxing.liu](/maintainers/jinxing.liu)

### Embed Badge

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

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

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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