Skip to content

Instantly share code, notes, and snippets.

@bakura10 bakura10/foo.php
Created Feb 14, 2014

Embed
What would you like to do?
<?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
You can’t perform that action at this time.