You can use callback
CURLOPT_READFUNCTION Pass a function that will be called to read data. Callback function prototype:
string read_callback (resource ch, resource fd, long length)
The ch parameter is a CURL session handle. The fd argument is a file descriptor passed to CURL using the CURLOPT_INFILE option. The length argument is the maximum length that can be returned. The function should return a string containing the read data. If the data length is greater than the maximum, then it will be truncated to the maximum length. Returning everything else but the string means EOF.
See curl_setopt .
source share