Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- Bug https://github.com/scoutapp/scout-apm-php-ext/issues/88 - memory usage should..

Decoded Output download

--TEST--
Bug https://github.com/scoutapp/scout-apm-php-ext/issues/88 - memory usage should not increase when no instrumentation happens
--SKIPIF--
<?php if (!extension_loaded("scoutapm")) die("skip scoutapm extension required."); ?>
<?php /* PHP_OS_FAMILY === "Windows" - needs PHP 7.2+ */ if (stripos(PHP_OS, 'Win') === 0) die("skip not for Windows."); ?>
--FILE--
<?php

class A {
  function b() {}
}

$a = new A();

scoutapm_enable_instrumentation(true);

$before = (int) (exec("ps --pid " . getmypid() . " --no-headers -o rss"));
for ($i = 0; $i <= 10000000; $i++) {
    $a->b();
}
$after = (int) (exec("ps --pid " . getmypid() . " --no-headers -o rss"));

echo "Before & after:
";
var_dump($before, $after);

echo "Difference:
";
var_dump($after - $before);

$threshold = 500; // bytes
echo "Within $threshold bytes limit:
";
var_dump(($after - $before) < $threshold);

?>
--EXPECTF--
Before & after:
int(%d)
int(%d)
Difference:
int(%d)
Within %d bytes limit:
bool(true)

Did this file decode correctly?

Original Code

--TEST--
Bug https://github.com/scoutapp/scout-apm-php-ext/issues/88 - memory usage should not increase when no instrumentation happens
--SKIPIF--
<?php if (!extension_loaded("scoutapm")) die("skip scoutapm extension required."); ?>
<?php /* PHP_OS_FAMILY === "Windows" - needs PHP 7.2+ */ if (stripos(PHP_OS, 'Win') === 0) die("skip not for Windows."); ?>
--FILE--
<?php

class A {
  function b() {}
}

$a = new A();

scoutapm_enable_instrumentation(true);

$before = (int) (exec("ps --pid " . getmypid() . " --no-headers -o rss"));
for ($i = 0; $i <= 10000000; $i++) {
    $a->b();
}
$after = (int) (exec("ps --pid " . getmypid() . " --no-headers -o rss"));

echo "Before & after:\n";
var_dump($before, $after);

echo "Difference:\n";
var_dump($after - $before);

$threshold = 500; // bytes
echo "Within $threshold bytes limit:\n";
var_dump(($after - $before) < $threshold);

?>
--EXPECTF--
Before & after:
int(%d)
int(%d)
Difference:
int(%d)
Within %d bytes limit:
bool(true)

Function Calls

extension_loaded 1

Variables

None

Stats

MD5 781e2e97540bd55f86fe9b78482870d5
Eval Count 0
Decode Time 90 ms