Skip to content

Instantly share code, notes, and snippets.

@ammarfaizi2
Last active October 9, 2018 08:16
Show Gist options
  • Save ammarfaizi2/14b4d00be6c2f3ff824742935c9c6444 to your computer and use it in GitHub Desktop.
Save ammarfaizi2/14b4d00be6c2f3ff824742935c9c6444 to your computer and use it in GitHub Desktop.
<?php
$errno = $error = NULL;
$host = "www.indopremier.com";
$handle = fsockopen("ssl://{$host}", 443, $errno, $error, 100);
if (is_resource($handle)) {
$requestHeaders =
"GET /module/saham/include/stock-streaming.php HTTP/1.1\r\n".
"Host: {$host}\r\n".
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linu…) Gecko/20100101 Firefox/61.0\r\n\r\n";
print "Sending HTTP headers...\n";
$part = 0;
if (fwrite($handle, $requestHeaders)) {
$first = fread($handle, 4096);
preg_match("/(.*)(?:\r\n){2}(.*)/Usi", $first, $m);
$responseHeader = $m[1];
$responseBody = $m[2];
while (!feof($handle)) {
$responseBody .= fread($handle, 1024);
$exp = explode("\n\n", $responseBody);
$arraySize = sizeof($exp);
if ($arraySize > 1) {
// Prevent uncomplete buffer to be saved.
$arraySize--;
for ($i=0; $i < $arraySize; $i++) {
print "Saving part {$part}...\n{$exp[$i]}";
file_put_contents("part_{$part}.txt", $exp[$i]);
$part++;
}
$responseBody = $exp[$arraySize];
}
}
}
} else {
printf("Error: (%d): %s\n", $errno, $error);
exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment