2017 © Pedro Peláez
 

library curl-header-extractor

Utility to extract headers from PHP CURL to file request.

image

dcarbone/curl-header-extractor

Utility to extract headers from PHP CURL to file request.

  • Tuesday, September 13, 2016
  • by dcarbone
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5,522 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 33 % Grown

The README.md

curl-header-extractor

Utility to extract headers from PHP CURL request., (*1)

Installation

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

Composer Require entry:, (*3)

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

Usage

There are 3 methods available:, (*4)

getHeaderAndBody

This method accepts a single argument that may be:, (*5)

  • 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:, (*6)

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., (*7)

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., (*8)

If you wish to extract JUST the headers, the below methods might serve you better., (*9)

extractHeadersAndBodyStartOffset

This method will return an array with the following structure:, (*10)

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., (*11)

removeHeadersAndMoveFile

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

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., (*13)

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)., (*14)

This allows you to do something like this:, (*15)

$extractor = new \DCarbone\CURLHeaderExtractor();

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

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

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

The Versions

13/09 2016

dev-master

9999999-dev

Utility to extract headers from PHP CURL to file request.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Daniel Carbone

curl file php http response extractor headers header

13/09 2016

2.0.3

2.0.3.0

Utility to extract headers from PHP CURL to file request.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Daniel Carbone

curl file php http response extractor headers header

08/07 2016

2.0.2

2.0.2.0

Utility to extract headers from PHP CURL to file request.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Daniel Carbone

curl file php http response extractor headers header

08/06 2016

2.0.1

2.0.1.0

Utility to extract headers from PHP CURL to file request.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Daniel Carbone

curl file php http response extractor headers header

08/06 2016

2.0.0

2.0.0.0

Utility to extract headers from PHP CURL to file request.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Daniel Carbone

curl file php http response extractor headers header

24/01 2016

1.0.0

1.0.0.0

Utility to extract headers from PHP CURL to file request.

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

by Daniel Carbone

curl file php http response extractor headers header