video: abort curl on termination
parent
a982416712
commit
8adedd1885
|
@ -237,6 +237,9 @@ class VideoController extends ApiBase
|
||||||
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
||||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||||
|
|
||||||
|
// Catch connection abort here
|
||||||
|
ignore_user_abort(true);
|
||||||
|
|
||||||
// Stream the response to the browser without reading it into memory
|
// Stream the response to the browser without reading it into memory
|
||||||
$headersWritten = false;
|
$headersWritten = false;
|
||||||
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) use (&$headersWritten) {
|
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) use (&$headersWritten) {
|
||||||
|
@ -248,13 +251,17 @@ class VideoController extends ApiBase
|
||||||
$headersWritten = true;
|
$headersWritten = true;
|
||||||
$contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
|
$contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
|
||||||
header("Content-Type: {$contentType}");
|
header("Content-Type: {$contentType}");
|
||||||
header("HTTP/1.1 {$returnCode}");
|
|
||||||
header('Cache-Control: no-cache, no-store, must-revalidate');
|
header('Cache-Control: no-cache, no-store, must-revalidate');
|
||||||
|
http_response_code($returnCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
print($data);
|
print($data);
|
||||||
ob_flush();
|
ob_flush();
|
||||||
flush();
|
flush();
|
||||||
|
|
||||||
|
if (connection_aborted()) {
|
||||||
|
return -1; // stop the transfer
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return strlen($data);
|
return strlen($data);
|
||||||
|
|
Loading…
Reference in New Issue