Title: Curl::stream_body
Published: March 29, 2023
Last modified: November 8, 2023

---

# Curl::stream_body( resource|CurlHandle $handle, string $data ): integer

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/stream_body/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/stream_body/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/stream_body/?output_format=md#source)
 * [Changelog](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/stream_body/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/stream_body/?output_format=md#wp--skip-link--target)

Collect data as it’s received

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/stream_body/?output_format=md#parameters)󠁿

 `$handle`resource|CurlHandlerequired

cURL handle

`$data`stringrequired

Body data

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/stream_body/?output_format=md#return)󠁿

 integer Length of provided data

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/stream_body/?output_format=md#source)󠁿

    ```php
     * @param string $data Body data
     * @return integer Length of provided data
     */
    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;
    	}
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/src/transport/curl.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/Requests/src/Transport/Curl.php#L534)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/Requests/src/Transport/Curl.php#L534-L560)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wporg-requests-transport-curl/stream_body/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.6.1](https://developer.wordpress.org/reference/since/1.6.1/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwporg-requests-transport-curl%2Fstream_body%2F)
before being able to contribute a note or feedback.