stop a curl transfer in the middle
I had a similar problem that needed me to be able to stop a curl transfer in the middle. This is easily in my personal top ten of 'dirty hacks that seem to work' of all time.
Create a curl read function that knows when it's time to cancel the upload.
function curlReadFunction($ch, $fileHandle, $maxDataSize){ if($GLOBALS['abortTransfer'] == TRUE){ sleep(1); return ""; } return fread($fileHandle, $maxDataSize);}
And tell Curl to stop if the data read rate drops too low for a certain amount of time.
curl_setopt($ch, CURLOPT_READFUNCTION, 'curlReadFunction');curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, 1024);curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, 5);
This will cause the curl transfer to abort during the upload. Obviously not ideal but it seems to work.