GC_Http_Curl::stream_body()

最后更新于:2021-12-01 11:13:05

GC_( resource$handle, string$data)

Grabs the body of the cURL request.

参数

$handle

(resource) (Required) cURL handle.

$data

(string) (Required) cURL request body.

响应

(int) Total bytes of data written.

源文件

文件: gc-includes/class-gc-http-curl.php

	private function stream_body( $handle, $data ) {
		$data_length = strlen( $data );

		if ( $this->max_body_length && ( $this->bytes_written_total + $data_length ) > $this->max_body_length ) {
			$data_length = ( $this->max_body_length - $this->bytes_written_total );
			$data        = substr( $data, 0, $data_length );
		}

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

		$this->bytes_written_total += $bytes_written;

		// Upon event of this function returning less than strlen( $data ) curl will error with CURLE_WRITE_ERROR.
		return $bytes_written;
	}