Skip to content

Instantly share code, notes, and snippets.

@bakura10
Created February 14, 2014 09:16
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 bakura10/8998123 to your computer and use it in GitHub Desktop.
Save bakura10/8998123 to your computer and use it in GitHub Desktop.
<?php
require __DIR__ . '/vendor/autoload.php';
use \Zend\EventManager\ListenerAggregateInterface;
use \Zend\EventManager\EventManagerInterface;
class Listener implements ListenerAggregateInterface
{
protected $bigService;
public function attach(EventManagerInterface $events)
{
$events->attach('foo', array($this, 'listen'));
}
public function detach(EventManagerInterface $events) {}
public function listen()
{
$bigService = $this->getBigService();
// do something
}
public function getBigService()
{
return $this->bigService;
}
public function setBigService($bigService)
{
$this->bigService = $bigService;
}
}
$proxy = new \ProxyManager\Factory\LazyLoadingGhostFactory();
$listener = $proxy->createProxy('Listener', function ($proxy, $method, $parameters, & $initializer) {
if ($method == 'getBigService') {
$proxy->setBigService(bigService());
}
});
$memory = memory_get_usage();
$eventManager = new \Zend\EventManager\EventManager();
$eventManager->attach($listener);
$memory = memory_get_usage() - $memory;
var_dump(round($memory/1000000, 2) . 'MB');
function bigService()
{
$s = array();
for ($i = 0; $i < 10000; $i++) {
$s[] = str_repeat('123456789', 200);
}
return $s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment