| Server IP : 170.10.162.208 / Your IP : 216.73.216.181 Web Server : LiteSpeed System : Linux altar19.supremepanel19.com 4.18.0-553.69.1.lve.el8.x86_64 #1 SMP Wed Aug 13 19:53:59 UTC 2025 x86_64 User : deltahospital ( 1806) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /tmp/ |
Upload File : |
--TEST--
Bug https://github.com/scoutapp/scout-apm-php-ext/issues/49 - only record arguments for fopen if it returns a resource
--SKIPIF--
<?php if (!extension_loaded("scoutapm")) die("skip scoutapm extension required."); ?>
--FILE--
<?php
scoutapm_enable_instrumentation(true);
// Note, in PHP 8 the warning changed from "failed to open stream" to "Failed to open stream" hence the %c
var_dump(fopen('/this/file/should/not/exist', 'r'));
var_dump(scoutapm_get_calls());
?>
--EXPECTF--
Warning: fopen(%s): %cailed to open stream: No such file or directory in %s
bool(false)
array(0) {
}
--TEST--
Running evaled code does not crash
--SKIPIF--
<?php if (!extension_loaded("scoutapm")) die("skip scoutapm extension required."); ?>
--FILE--
<?php
scoutapm_enable_instrumentation(true);
eval('echo "Evaled code called.\n";');
echo "End.\n";
?>
--EXPECTF--
Evaled code called.
End.
--TEST--
Calls to file_get_contents are logged
--SKIPIF--
<?php if (!extension_loaded("scoutapm")) die("skip scoutapm extension required."); ?>
--FILE--
<?php
var_dump(in_array('file_get_contents', scoutapm_list_instrumented_functions()));
scoutapm_enable_instrumentation(true);
file_get_contents(__FILE__);
$call = scoutapm_get_calls()[0];
var_dump($call['function']);
var_dump($call['entered']);
var_dump($call['exited']);
var_dump($call['time_taken']);
var_dump($call['exited'] > $call['entered']);
var_dump($call['argv']);
?>
--EXPECTF--
bool(true)
string(17) "file_get_contents"
float(%f)
float(%f)
float(%f)
bool(true)
array(1) {
[0]=>
string(%d) "%s%etests%e002-file_get_contents.php"
}
--TEST--
Calls to fwrite and fread are logged with handle from tmpfile()
--SKIPIF--
<?php if (!extension_loaded("scoutapm")) die("skip scoutapm extension required."); ?>
--FILE--
<?php
var_dump(in_array('fread', scoutapm_list_instrumented_functions()));
var_dump(in_array('fwrite', scoutapm_list_instrumented_functions()));
scoutapm_enable_instrumentation(true);
$fh = tmpfile();
fwrite($fh, "fread/fwrite test\n");
fseek($fh, 0);
echo fread($fh, 18);
fclose($fh);
$calls = scoutapm_get_calls();
var_dump($calls[0]['function']);
var_dump($calls[0]['argv']);
var_dump($calls[1]['function']);
var_dump($calls[1]['argv']);
?>
--EXPECTF--
bool(true)
bool(true)
fread/fwrite test
string(6) "fwrite"
array(2) {
[0]=>
string(%d) "resource(%d)"
[1]=>
string(18) "fread/fwrite test
"
}
string(5) "fread"
array(2) {
[0]=>
string(%d) "resource(%d)"
[1]=>
int(18)
}
--TEST--
Memcached C extension functions are instrumented
--SKIPIF--
<?php
if (!extension_loaded("scoutapm")) die("skip scoutapm extension required.");
if (!extension_loaded("memcached")) die("skip memcached extension required.");
if (!getenv('CI')) {
// Check Memcached is running & can connect to it
// Run with: docker run --rm --name memcached -p 11211:11211 -d memcached
$m = new Memcached();
$m->addServer('localhost', 11211);
if (!$m->flush()) {
die("skip Could not connect to Memcached - is it running?");
}
}
?>
--FILE--
<?php
echo implode("\n", array_intersect(
[
'memcached->add',
'memcached->addbykey',
'memcached->append',
'memcached->appendbykey',
'memcached->cas',
'memcached->decrement',
'memcached->decrementbykey',
'memcached->delete',
'memcached->deletebykey',
'memcached->deletemulti',
'memcached->deletemultibykey',
'memcached->flush',
'memcached->get',
'memcached->getallkeys',
'memcached->getbykey',
'memcached->getmulti',
'memcached->getmultibykey',
'memcached->increment',
'memcached->incrementbykey',
'memcached->prepend',
'memcached->prependbykey',
'memcached->replace',
'memcached->replacebykey',
'memcached->set',
'memcached->setbykey',
'memcached->setmulti',
'memcached->setmultibykey',
],
scoutapm_list_instrumented_functions()
)) . "\n";
scoutapm_enable_instrumentation(true);
$m = new Memcached();
$m->addServer('localhost', 11211);
$m->setOption(Memcached::OPT_COMPRESSION, false);
$m->set('foo', 'bar');
var_dump($m->get('foo'));
$m->append('foo', 'baz');
$m->prepend('foo', 'gaz');
$m->replace('foo', 'bar');
$m->cas(0, 'foo', 'bar');
$m->add('num', 1);
$m->decrement('num');
$m->increment('num');
$m->delete('num');
$m->setMulti(['a' => 'a', 'b' => 'b']);
$m->getMulti(['a', 'b']);
$m->deleteMulti(['a', 'b']);
$m->setByKey('key', 'foo', 'bar');
$m->getByKey('key', 'foo');
$m->appendByKey('key', 'foo', 'baz');
$m->prependByKey('key', 'foo', 'gaz');
$m->replaceByKey('key', 'foo', 'bar');
$m->casByKey(0, 'key', 'foo', 'bar');
$m->addByKey('key', 'num', 1);
$m->decrementByKey('key', 'num');
$m->incrementByKey('key', 'num');
$m->deleteByKey('key', 'num');
$m->setMultiByKey('key', ['a' => 'a', 'b' => 'b']);
$m->getMultiByKey('key', ['a', 'b']);
$m->deleteMultiByKey('key', ['a', 'b']);
$m->getAllKeys();
$m->flush();
$calls = scoutapm_get_calls();
var_dump(array_column($calls, 'function'));
?>
--EXPECTF--
memcached->add
memcached->addbykey
memcached->append
memcached->appendbykey
memcached->cas
memcached->decrement
memcached->decrementbykey
memcached->delete
memcached->deletebykey
memcached->deletemulti
memcached->deletemultibykey
memcached->flush
memcached->get
memcached->getallkeys
memcached->getbykey
memcached->getmulti
memcached->getmultibykey
memcached->increment
memcached->incrementbykey
memcached->prepend
memcached->prependbykey
memcached->replace
memcached->replacebykey
memcached->set
memcached->setbykey
memcached->setmulti
memcached->setmultibykey
string(%s) "bar"
array(%d) {
[%d]=>
string(%d) "Memcached->set"
[%d]=>
string(%d) "Memcached->get"
[%d]=>
string(%d) "Memcached->append"
[%d]=>
string(%d) "Memcached->prepend"
[%d]=>
string(%d) "Memcached->replace"
[%d]=>
string(%d) "Memcached->cas"
[%d]=>
string(%d) "Memcached->add"
[%d]=>
string(%d) "Memcached->decrement"
[%d]=>
string(%d) "Memcached->increment"
[%d]=>
string(%d) "Memcached->delete"
[%d]=>
string(%d) "Memcached->setMulti"
[%d]=>
string(%d) "Memcached->getMulti"
[%d]=>
string(%d) "Memcached->deleteMulti"
[%d]=>
string(%d) "Memcached->setByKey"
[%d]=>
string(%d) "Memcached->getByKey"
[%d]=>
string(%d) "Memcached->appendByKey"
[%d]=>
string(%d) "Memcached->prependByKey"
[%d]=>
string(%d) "Memcached->replaceByKey"
[%d]=>
string(%d) "Memcached->casByKey"
[%d]=>
string(%d) "Memcached->addByKey"
[%d]=>
string(%d) "Memcached->decrementByKey"
[%d]=>
string(%d) "Memcached->incrementByKey"
[%d]=>
string(%d) "Memcached->deleteByKey"
[%d]=>
string(%d) "Memcached->setMultiByKey"
[%d]=>
string(%d) "Memcached->getMultiByKey"
[%d]=>
string(%d) "Memcached->deleteMultiByKey"
[%d]=>
string(%d) "Memcached->getAllKeys"
[%d]=>
string(%d) "Memcached->flush"
}
--TEST--
Check Scout APM extension is loaded
--FILE--
<?php
ob_start();
phpinfo(INFO_GENERAL);
$phpinfo = ob_get_clean();
foreach (explode("\n", $phpinfo) as $line) {
if (stripos($line, ' with scoutapm') === 0) {
var_dump($line);
}
}
var_dump(extension_loaded('scoutapm'));
?>
--EXPECTF--
string(%d) " with scoutapm v%s, Copyright %d, by Scout APM"
bool(true)
--TEST--
Predis userland functions are supported
--SKIPIF--
<?php
if (!extension_loaded("scoutapm")) die("skip scoutapm extension required.");
if (shell_exec("which composer") === null) die("skip composer not found in path.");
$out = null;
$result = null;
exec("mkdir -p /tmp/scout_predis_test && cd /tmp/scout_predis_test && composer require -n predis/predis", $out, $result);
if ($result !== 0) {
die("skip composer failed: " . implode(", ", $out));
}
if (!getenv('CI')) {
require "/tmp/scout_predis_test/vendor/autoload.php";
// Check Redis is running & can connect to it
// Run with: docker run --rm --name redis -p 6379:6379 -d redis
$client = new \Predis\Client();
try {
$client->connect();
} catch (\Predis\Connection\ConnectionException $e) {
die("skip " . $e->getMessage());
}
}
?>
--FILE--
<?php
echo implode("\n", array_intersect(
[
'Predis\Client->append',
'Predis\Client->decr',
'Predis\Client->decrBy',
'Predis\Client->get',
'Predis\Client->getBit',
'Predis\Client->getRange',
'Predis\Client->getSet',
'Predis\Client->incr',
'Predis\Client->incrBy',
'Predis\Client->mGet',
'Predis\Client->mSet',
'Predis\Client->mSetNx',
'Predis\Client->set',
'Predis\Client->setBit',
'Predis\Client->setEx',
'Predis\Client->pSetEx',
'Predis\Client->setNx',
'Predis\Client->setRange',
'Predis\Client->strlen',
'Predis\Client->del',
],
scoutapm_list_instrumented_functions()
)) . "\n";
scoutapm_enable_instrumentation(true);
require "/tmp/scout_predis_test/vendor/autoload.php";
$client = new \Predis\Client();
// Simple operations
$client->set('foo', 'bar');
var_dump($client->get('foo'));
$client->append('foo', 'baz');
$client->del('foo');
$client->getSet('foo', 'bat');
$client->getRange('foo', 0, 2);
$client->setRange('foo', 0, 'qux');
$client->setEx('expire1', 1, 'value1');
$client->pSetEx('expire2', 1, 'value2');
$client->setNx('fuu', 'new');
$client->strlen('fuu');
// Increment/Decrement
$client->set('count', 0);
$client->incr('count');
$client->decr('count');
$client->incrBy('count', 2);
$client->decrBy('count', 2);
// Multi-operations
$client->mSet(['a' => 'a', 'b' => 'b']);
$client->mSetNx(['c' => 'c', 'd' => 'd']);
$client->mGet(['a', 'b', 'c', 'd']);
// Bit operations
$client->set('bit', 0);
$client->setBit('bit', 8, 1);
$client->getBit('bit', 8);
$calls = scoutapm_get_calls();
var_dump(array_column($calls, 'function'));
?>
--CLEAN--
<?php
shell_exec("rm -Rf /tmp/scout_predis_test");
?>
--EXPECTF--
Predis\Client->append
Predis\Client->decr
Predis\Client->decrBy
Predis\Client->get
Predis\Client->getBit
Predis\Client->getRange
Predis\Client->getSet
Predis\Client->incr
Predis\Client->incrBy
Predis\Client->mGet
Predis\Client->mSet
Predis\Client->mSetNx
Predis\Client->set
Predis\Client->setBit
Predis\Client->setEx
Predis\Client->pSetEx
Predis\Client->setNx
Predis\Client->setRange
Predis\Client->strlen
Predis\Client->del
string(%s) "bar"
array(%d) {
[%d]=>
string(%d) "Predis\Client->set"
[%d]=>
string(%d) "Predis\Client->get"
[%d]=>
string(%d) "Predis\Client->append"
[%d]=>
string(%d) "Predis\Client->del"
[%d]=>
string(%d) "Predis\Client->getSet"
[%d]=>
string(%d) "Predis\Client->getRange"
[%d]=>
string(%d) "Predis\Client->setRange"
[%d]=>
string(%d) "Predis\Client->setEx"
[%d]=>
string(%d) "Predis\Client->pSetEx"
[%d]=>
string(%d) "Predis\Client->setNx"
[%d]=>
string(%d) "Predis\Client->strlen"
[%d]=>
string(%d) "Predis\Client->set"
[%d]=>
string(%d) "Predis\Client->incr"
[%d]=>
string(%d) "Predis\Client->decr"
[%d]=>
string(%d) "Predis\Client->incrBy"
[%d]=>
string(%d) "Predis\Client->decrBy"
[%d]=>
string(%d) "Predis\Client->mSet"
[%d]=>
string(%d) "Predis\Client->mSetNx"
[%d]=>
string(%d) "Predis\Client->mGet"
[%d]=>
string(%d) "Predis\Client->set"
[%d]=>
string(%d) "Predis\Client->setBit"
[%d]=>
string(%d) "Predis\Client->getBit"
}
--TEST--
Bug https://github.com/scoutapp/scout-apm-php-ext/issues/71 - only record arguments for prepare if it returns an object
--SKIPIF--
<?php if (!extension_loaded("scoutapm")) die("skip scoutapm extension required."); ?>
<?php if (!extension_loaded("PDO")) die("skip PDO extension required."); ?>
<?php if (!extension_loaded("pdo_sqlite")) die("skip pdo_sqlite extension required."); ?>
--FILE--
<?php
scoutapm_enable_instrumentation(true);
$dbh = new PDO('sqlite::memory:');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$stmt = $dbh->prepare("SELECT nonexist FROM nonexist");
?>
--EXPECTF--
Warning: PDO::prepare(): SQLSTATE[HY000]: General error: 1 no such table: nonexist in %s
--TEST--
Bug https://github.com/scoutapp/scout-apm-php-ext/issues/55 - don't crash when using an observed method in extended class
--SKIPIF--
<?php if (!extension_loaded("scoutapm")) die("skip scoutapm extension required."); ?>
<?php if (!extension_loaded("PDO")) die("skip PDO extension required."); ?>
<?php if (!extension_loaded("pdo_sqlite")) die("skip pdo_sqlite extension required."); ?>
--FILE--
<?php
scoutapm_enable_instrumentation(true);
class MyOwnPDO extends PDO {}
$dbh = new MyOwnPDO('sqlite::memory:');
$stmt = $dbh->query("SELECT cast(1 + 2 AS text) AS result");
var_dump($stmt->fetch(PDO::FETCH_ASSOC));
$calls = scoutapm_get_calls();
var_dump($calls[0]['function']);
var_dump($calls[0]['argv'][0]);
?>
--EXPECTF--
array(%d) {
["result"]=>
string(%d) "3"
}
string(%d) "PDO->query"
string(%d) "SELECT cast(1 + 2 AS text) AS result"
--TEST--
Calls to PDO::exec are logged
--SKIPIF--
<?php if (!extension_loaded("scoutapm")) die("skip scoutapm extension required."); ?>
<?php if (!extension_loaded("PDO")) die("skip PDO extension required."); ?>
<?php if (!extension_loaded("pdo_sqlite")) die("skip pdo_sqlite extension required."); ?>
--FILE--
<?php
var_dump(in_array('pdo->exec', scoutapm_list_instrumented_functions()));
scoutapm_enable_instrumentation(true);
$dbh = new PDO('sqlite::memory:');
$dbh->exec("CREATE TABLE foo (col INT PRIMARY KEY)");
$dbh->exec("INSERT INTO foo (col) VALUES (1), (2) ");
$calls = scoutapm_get_calls();
var_dump($calls[0]['function']);
var_dump($calls[0]['argv'][0]);
var_dump($calls[1]['function']);
var_dump($calls[1]['argv'][0]);
?>
--EXPECTF--
bool(true)
string(9) "PDO->exec"
string(38) "CREATE TABLE foo (col INT PRIMARY KEY)"
string(9) "PDO->exec"
string(38) "INSERT INTO foo (col) VALUES (1), (2) "
--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)