Requests_Transport_cURL::stream_body() WordPress Method

The Requests_Transport_cURL::stream_body() method is used to retrieve the body of a response from a remote server using the cURL library. This is useful for retrieving large amounts of data from a server, as it allows the data to be streamed directly to the client without having to first download it all to the server.

Requests_Transport_cURL::stream_body( resource $handle, string $data ) #

Collect data as it’s received


Parameters

$handle

(resource)(Required)cURL resource

$data

(string)(Required)Body data


Top ↑

Return

(integer) Length of provided data


Top ↑

Source

File: wp-includes/Requests/Transport/cURL.php

	public function stream_body($handle, $data) {
		$this->hooks->dispatch('request.progress', array($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;
	}

Top ↑

Changelog

Changelog
VersionDescription
1.6.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.