Skip to content

Instantly share code, notes, and snippets.

@freshteapot
Last active December 12, 2015 05:18
Show Gist options
  • Save freshteapot/4720707 to your computer and use it in GitHub Desktop.
Save freshteapot/4720707 to your computer and use it in GitHub Desktop.
Sample of streaming data to a server. - Make sure php://input has not been used first. - Start with this then work it into your code so you know it works. - The client end, should returns small amounts for memory_get_usage even when you have a very large file.
<?php
echo memory_get_usage() . "\n";
$fileName = "/tmp/postedData";
$f = fopen($fileName, "w");
$s = fopen("php://input", "r");
while($kb = fread($s, 1024)) {
fwrite($f, $kb, 1024);
}
fclose($f);
fclose($s);
echo memory_get_usage() . "\n";
echo "\n\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment