我使用以下代码:
class SplitCurlByLines {
public function curlCallback($curl, $data) {
$this->currentLine .= $data;
$lines = explode("\n", $this->currentLine);
// The last line could be unfinished. We should not
// proccess it yet.
$numLines = count($lines) - 1;
$this->currentLine = $lines[$numLines]; // Save for the next callback.
for ($i = 0; $i < $numLines; ++$i) {
$this->processLine($lines[$i]); // Do whatever you want
++$this->totalLineCount; // Statistics.
$this->totalLength += strlen($lines[$i]) + 1;
}
return strlen($data); // Ask curl for more data (!= value will stop).
}
public function processLine($str) {
// Do what ever you want (split CSV, ...).
echo $str . "\n";
}
public $currentLine = '';
public $totalLineCount = 0;
public $totalLength = 0;
} // SplitCurlByLines
$splitter = new SplitCurlByLines();
$ch = curl_init();
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 3.3.69573; WOW64; en-US)" );
curl_setopt( $ch, CURLOPT_URL, $URL );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_ENCODING, "" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); # required for https urls
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 0 );
curl_setopt( $ch, CURLOPT_TIMEOUT, 0 );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt( $ch, CURLOPT_WRITEFUNCTION, array($splitter, 'curlCallback') );
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Connection: Keep-Alive',
'Keep-Alive: 0'
));
$content = curl_exec( $ch );
$response = curl_getinfo( $ch );
header('Content-Transfer-Encoding: binary');
header('HTTP/1.1 206 Partial Content');
header('Accept-Ranges: bytes');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Content-Length: ' . $response['download_content_length']);
header('Content-Range: bytes ' . $offset . '-' . ($offset + $length) . '/' . $response['download_content_length']);
$splitter->processLine($splitter->currentLine);
curl_close ( $ch );
播放MP4视频从其他网站抓取,但在我使用HTML5视频后,它不允许我跳过时间,所以我该怎么做?
我使用的是PHP7和Apache2。