Skip to content

Instantly share code, notes, and snippets.

@mirfilip
Created July 27, 2017 12:47
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 mirfilip/daefd07cc22b703fe807ce041339f30a to your computer and use it in GitHub Desktop.
Save mirfilip/daefd07cc22b703fe807ce041339f30a to your computer and use it in GitHub Desktop.
Testing memory usage of Feed-IO
<?php
require __DIR__."/vendor/autoload.php";
$client = new GuzzleHttp\Client();
$feed = $argv[1];
echo "Reading $feed" . PHP_EOL . PHP_EOL;
print_mem_usage('before request');
$res = $client->request('GET', $feed);
print_mem_usage('after request');
echo "stream size (PSR way) : {$res->getBody()->getSize()}" . PHP_EOL;
print_mem_usage('after reading stream size (PSR way)');
echo "stream size (strlen) : " . strlen($res->getBody()) . PHP_EOL;
print_mem_usage('after reading stream size (strlen)');
function print_mem_usage($step)
{
echo "{$step}" . PHP_EOL;
echo "allocated to PHP: " . memory_get_usage(true) . PHP_EOL;
echo "Used by PHP: " . memory_get_usage() . PHP_EOL;
echo "Used at peak: " . memory_get_peak_usage() . PHP_EOL;
echo "------" . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment