Re: [PHP] > 120 meg of json analyzed by the browser...

2010-01-28 Thread Rene Veerman
On Thu, Jan 28, 2010 at 4:04 PM, Robert Cummings  wrote:
> Use get_memory() to see just how much memory you're using. Somewhere in your
> script you are probably storing much more memory than you think.

My functions do print the memory usage;
I'm just wondering why the array returned is 1/5th of the desired (and
allocated) size.


global $hmGenKeys;
$hmGenKeys = 0;
global $hmGenKeysDone;
$hmGenKeysDone = 0;
function htmlMicroscope_generateRandomArray ($maxKeys, $maxDepth,
$maxDuration=-1, $maxMem=-1) {
  global $hmGenKeys;
  global $hmGenKeysDone;

  $r = array();
  $l1 = false;
  if ($maxKeys!==null) {
$hmGenKeys = $maxKeys;
$l1 = true;
  }

  $hmGenKeys--;
  if ($hmGenKeys<=0) return false;
  if ($maxDepth<=0) return false;
  if ($l1) {
srand(htmlMicroscope_randMakeSeed());
while ($hmGenKeys > 0) {
$hmGenKeys--;
$hmGenKeysDone++;
file_put_contents('countdown.txt',
'k:'.number_format($hmGenKeysDone,0,'.',',').
' m:'.number_format(memory_get_usage(true),0,'.',',')
);
if ($maxMem!=-1 && memory_get_usage(true) > $maxMem) return $r;
if ($maxDuration!=-1 && $maxDuration < getDuration()) return $r;

switch (rand(1,2)) {
  case 1 :
$next = htmlMicroscope_generateRandomArray (null, $maxDepth-1,
$maxDuration, $maxMem);
if ($next!==false)
  $r +=  array(
htmlMicroscope_randomValue(4) => $next
  );
break;
  case 2 :
$r += array(
  htmlMicroscope_randomValue(4) => htmlMicroscope_randomValue(20)
);
break;
}
}
  } else {
$range = rand(0,50);
for ($i=0; $i<$range; $i++) {
$hmGenKeys--;
$hmGenKeysDone++;
file_put_contents('countdown.txt',
'k:'.number_format($hmGenKeysDone,0,'.',',').
' m:'.number_format(memory_get_usage(true),0,'.',',')
);
if ($maxMem!=-1 && memory_get_usage(true) > $maxMem) return $r;
if ($maxDuration!=-1 && $maxDuration < getDuration()) return $r;

switch (rand(1,2)) {
  case 1 :
$next = htmlMicroscope_generateRandomArray (null, $maxDepth-1,
$maxDuration, $maxMem);
if ($next!==false)
  $r +=  array(
htmlMicroscope_randomValue(4) => $next
  );
break;
  case 2 :
$r += array(
  htmlMicroscope_randomValue(4) => htmlMicroscope_randomValue(20)
);
break;
}
}
  }

  if (($hmGenKeysDone/7919)==round($hmGenKeysDone/7919)) sleep(1);

  return $r;
}

function htmlMicroscope_randomValue($maxLength) {
  $r = '';
  switch (rand(0,9)) {
case 0 : $r = rand (0,1); break;
case 1 : $r = rand (0,1) / rand(1,100) / 3; break;
default:
switch (rand(0,1)) {
  case 0:
  $rnd = rand(1,$maxDepth);
for ($i = 0; $i < $rnd; $i++) {
  $r.= unichr(rand(0,hexdec('')));
}
break;
  case 1:
for ($i = 0; $i < $maxLength; $i++) {
  $r.=chr(rand(ord('a'),ord('z')));;
}
break;
}
break;
  }
  //echo $r.''.$maxLength.'';
  return $r;
}

function htmlMicroscope_randMakeSeed() {
  list($usec, $sec) = explode(' ', microtime());
  return (float) $sec + ((float) $usec * 10);
}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] > 120 meg of json analyzed by the browser...

2010-01-28 Thread Robert Cummings

Rene Veerman wrote:

Hi..

I've built http://mediabeez.ws/htmlMicroscope/ (lgpl), which provides
a way to look at very big arrays in the browser.

I'm kinda stuck at a 120 - 200Mb data-size limit, and have exhausted
all my ideas on how to increase that limit further.
My reasoning is that i have a gigabyte free memory on my machine, and
want to use that to look at an array of at least 800mb.
I know, it's a totally academic feature at the moment.

But still, i would like feedback on how to increase the datasize limit
to actual-free-RAM.
If it's at all possible.
I would greatly appreciate feedback from webbrowser developers.

If you have some time and energy, please download the 1.3.0-beta on my
site, and have a look to see if you can find something to improve.


Use get_memory() to see just how much memory you're using. Somewhere in 
your script you are probably storing much more memory than you think.


Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] > 120 meg of json analyzed by the browser...

2010-01-28 Thread Rene Veerman
Hi..

I've built http://mediabeez.ws/htmlMicroscope/ (lgpl), which provides
a way to look at very big arrays in the browser.

I'm kinda stuck at a 120 - 200Mb data-size limit, and have exhausted
all my ideas on how to increase that limit further.
My reasoning is that i have a gigabyte free memory on my machine, and
want to use that to look at an array of at least 800mb.
I know, it's a totally academic feature at the moment.

But still, i would like feedback on how to increase the datasize limit
to actual-free-RAM.
If it's at all possible.
I would greatly appreciate feedback from webbrowser developers.

If you have some time and energy, please download the 1.3.0-beta on my
site, and have a look to see if you can find something to improve.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php