Home >Backend Development >PHP Tutorial >## Why Does Curl Return \'18: transfer closed with outstanding read data remaining\' When Using CURLOPT_RETURNTRANSFER?
Addressing the Transfer Closed Error with Outstanding Read Data
Executing a data retrieval with curl may occasionally yield an error message, particularly when using CURLOPT_RETURNTRANSFER to store the data for later retrieval. This error, "18: transfer closed with outstanding read data remaining," can result in incomplete data.
One notable aspect is that this error does not occur when CURLOPT_RETURNTRANSFER is set to false, leading to the data being displayed directly. This behavior raises questions about potential underlying issues.
Understanding the Error
The error message essentially indicates that libcurl identifies incomplete chunk reception within a chunked encoding stream. When the connection is closed prematurely, libcurl recognizes that the last received chunk was unfinished. This recognition triggers the error code.
Addressing the Issue
Eliminating this error with an unaltered request is not feasible. However, a workaround exists by issuing a HTTP 1.0 request instead, as chunked encoding is not employed in this version. Nonetheless, it is essential to recognize that this error is likely a network, server, or setup-related problem that should be investigated further.
The above is the detailed content of ## Why Does Curl Return \'18: transfer closed with outstanding read data remaining\' When Using CURLOPT_RETURNTRANSFER?. For more information, please follow other related articles on the PHP Chinese website!