Skip to content

Instantly share code, notes, and snippets.

@nextend
Created October 13, 2021 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nextend/61bb5a8b36ea126f3e95297f3f7de10e to your computer and use it in GitHub Desktop.
Save nextend/61bb5a8b36ea126f3e95297f3f7de10e to your computer and use it in GitHub Desktop.
<?php
class Test {
protected $handle;
protected $data = '';
private $chunkIndex = 0;
public function __construct() {
$url = "*****";
$this->handle = curl_init($url);
curl_setopt($this->handle, CURLOPT_WRITEFUNCTION, array(
$this,
'stream_body'
));
curl_setopt($this->handle, CURLOPT_BUFFERSIZE, 1160);
curl_exec($this->handle);
curl_close($this->handle);
$md5 = md5($this->data);
if ($md5 !== '231732259d67fe83ed6fc02d7ad9be57') {
echo "<h1>Error, not valid md5</h1>";
}
echo "<h1>" . $md5 . "</h1>";
}
public function stream_body($handle, $data) {
$data_length = strlen($data);
$this->data.= $data;
echo 'Chunk #' . ($this->chunkIndex++) . ': ' . md5($data) . ' '.$data_length.'<br>';
return $data_length;
}
}
new Test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment