Skip to content

Instantly share code, notes, and snippets.

@tvlooy
Last active December 14, 2015 06:19
Show Gist options
  • Save tvlooy/5041906 to your computer and use it in GitHub Desktop.
Save tvlooy/5041906 to your computer and use it in GitHub Desktop.
log memory usage of a Symfony2 action
<?php
class SomeController extends Controller
{
public function someAction()
{
$dispatcher = $this->get('event_dispatcher');
$dispatcher->addListener('kernel.response', function (\Symfony\Component\EventDispatcher\Event $event) {
file_put_contents(
'/tmp/memory_logger.txt',
date("Y-m-d H:i:s") . ' used ' . number_format(memory_get_usage() / 1024 / 1024, 2) . " MB\n",
FILE_APPEND
);
});
/* your actual code ... */
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment