replace TIMEOUT with CONNECTTIMEOUT
replace TIMEOUT with CONNECTTIMEOUT

use CURLOPT_CONNECTTIMEOUT instead of CURLOPT_TIMEOUT
CURLOPT_CONNECTTIMEOUT  contain the maximum time in seconds that you allow the connection phase to the server to take. This only limits the connection phase, it has no impact once it has connected
CURLOPT_TIMEOUT is for the entire operation which could cause partial download
abdul202/php-cURL-class