定制 dcarbone/curl-header-extractor 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dcarbone/curl-header-extractor

最新稳定版本:v3.0.3

Composer 安装命令:

composer require dcarbone/curl-header-extractor

包简介

Utility to extract headers from PHP CURL to file request.

README 文档

README

Utility to extract headers from PHP CURL request.

Installation

While it is advisable to use Composer, this lib is simple enough to be used without it.

Composer Require entry:

{
    "dcarbone/curl-header-extractor": "v3.0.*"
}

Usage

There are 3 methods available:

getHeaderAndBody

This method accepts a single argument that may be:

  • Full path to the file
  • File resource created with fopen with at least read permissions.
  • String of response data

The response will be an array with the following structure:

array(
    // array of headers,
    // string of body content
);

Example:

list($headers, $body) = \DCarbone\CURLHeaderExtractor::getHeaderAndBody($input);

where $headers will be an array of headers, or NULL if no headers were found, and $body will be the entire contents of the body.

Note:

This method CAN be very expensive to use if you are working with particularly large responses, as the end result will be the entire contents of the file loaded into memory.

If you wish to extract JUST the headers, the below methods might serve you better.

extractHeadersAndBodyStartOffset

This method will return an array with the following structure:

array(
    // array of headers,
    // integer representing the byte offset of the beginning of the body
);

Example:

list($headers, $bodyByteOffset) = \DCarbone\CURLHeaderExtractor::extractHeadersAndBodyStartOffset($input);

If no headers were seen in the file, $headers in the above example will be NULL and the byte offset will be 0.

removeHeadersAndMoveFile

This method will strip the file of the headers, copy the body to a new file, and then delete the old file.

Example:

\DCarbone\CURLHeaderExtractor::removeHeadersAndMoveFile($file, 'my_new_filename.ext');

If you executed the extractHeadersAndBodyStartOffset method already, you may pass in the body start offset integer in as the 3rd argument.

Invoking

To make this class easier to work with as a "helper", it implements the PHP magic method __invoke (you can see the implementation here).

This allows you to do something like this:

$extractor = new \DCarbone\CURLHeaderExtractor();

list($headers, $body) = $extractor($input);

You can, of course, access the other methods as you normally would any static method:

list($headers, $bodyByteOffset) = $extractor::extractHeadersAndBodyStartOffset($input);

统计信息

  • 总下载量: 63.76k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-06-08