<?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