Byte Ranges

Like cURL, pecl_http includes request options for a single resume point and multiple byte ranges. The former is ' resume’ and accepts an integer for the starting point. The latter is ' range’ and is formatted as an array of enumerated arrays each containing a pair of integers representing a single byte range. What follows is an example of setting byte ranges within a request options array.

<?php
$opts = array(
'range' => array(
array(0, 1023), // first 1024 bytes (KB)
array(3072, 4095) // fourth 1024 bytes (KB)
)
);
?>

Alternatively, it can be set using custom headers via the ' headers’ request option.

<?php
$opts = array(
'headers' => array(
'User-Agent' => 'Mozilla/5.0 (X11; U; ...',
'Connection' => 'keep-alive'
)
);
?>

 


© pecl_http PECL Extension — Web Scraping

>>> Back to TABLE OF CONTENTS <<<
Category: Article | Added by: Marsipan (31.08.2014)
Views: 410 | Rating: 0.0/0
Total comments: 0
avatar