WpOrg\Requests\Transport

Curl::stream_body()publicWP 1.6.1

Collect data as it's received

Method of the class: Curl{}

No Hooks.

Return

Int. Length of provided data

Usage

$Curl = new Curl();
$Curl->stream_body( $handle, $data );
$handle(resource|\CurlHandle) (required)
cURL handle
$data(string) (required)
Body data

Changelog

Since 1.6.1 Introduced.

Curl::stream_body() code WP 6.6.2

public function stream_body($handle, $data) {
	$this->hooks->dispatch('request.progress', [$data, $this->response_bytes, $this->response_byte_limit]);
	$data_length = strlen($data);

	// Are we limiting the response size?
	if ($this->response_byte_limit) {
		if ($this->response_bytes === $this->response_byte_limit) {
			// Already at maximum, move on
			return $data_length;
		}

		if (($this->response_bytes + $data_length) > $this->response_byte_limit) {
			// Limit the length
			$limited_length = ($this->response_byte_limit - $this->response_bytes);
			$data           = substr($data, 0, $limited_length);
		}
	}

	if ($this->stream_handle) {
		fwrite($this->stream_handle, $data);
	} else {
		$this->response_data .= $data;
	}

	$this->response_bytes += strlen($data);
	return $data_length;
}