Permalink
Browse files

Basic probe for PHP (#4)

  • Loading branch information...
dcieslak committed Oct 15, 2013
1 parent 8c78b2d commit 847de282d0b689d6c1ee214a6f1fa5f504a7b8ad
Showing with 91 additions and 0 deletions.
  1. +1 −0 Makefile
  2. +7 −0 src/probes/php/Makefile
  3. +2 −0 src/probes/php/README.txt
  4. +59 −0 src/probes/php/randomtest-probe.php
  5. +22 −0 src/probes/php/test1.php
View
@@ -5,6 +5,7 @@ build:
test:
make -C src/probes/c test
make -C src/probes/php test
clean:
make -C src/probes/c clean
View
@@ -0,0 +1,7 @@
all: test
test:
php test1.php
@@ -0,0 +1,2 @@
php5-curl module must be installed.
@@ -0,0 +1,59 @@
<?php
/*
Copyright: randomtest.net
*/
function format_backtrace($frameSkip = 2) {
$trace = '';
foreach (debug_backtrace() as $frameOffset => $frameInfo) {
if ($frameOffset < $frameSkip) {
continue;
}
$file = $frameInfo['file'];
$line = $frameInfo['line'];
$function = $frameInfo['function'];
$trace .= "$file:$line $function\n";
}
return $trace;
}
function send_stacktrace ($comment) {
$RANDOMTEST_URL = getenv("RANDOMTEST_URL");
if (!$RANDOMTEST_URL) {
trigger_error("missing RANDOMTEST_URL in environment, skipping report");
return true;
}
$handle = curl_init();
$stacktrace = format_backtrace(2);
$stacktraceWithDecor = "BEGIN RANDOMTEST EVENT\n$comment\n${stacktrace}END RANDOMTEST EVENT\n";
$encodedStacktrace = urlencode($stacktraceWithDecor);
curl_setopt($handle, CURLOPT_URL, $RANDOMTEST_URL);
curl_setopt($handle, CURLOPT_POST, 1);
curl_setopt($handle, CURLOPT_POSTFIELDS, "stacktrace=$encodedStacktrace");
curl_exec($handle);
curl_close($handle);
return true;
}
function randomtest_error_handler ($num, $str, $file, $line, $context = null) {
send_stacktrace("$str");
}
function randomtest_exception_handler (Exception $e) {
send_stacktrace("$e");
}
error_reporting(E_ALL);
set_error_handler("randomtest_error_handler", E_ALL | E_STRICT);
set_exception_handler("randomtest_exception_handler");
?>
View
@@ -0,0 +1,22 @@
<?php
require("randomtest-probe.php");
function fun_A($arr) {
return $arr[10];
}
function fun_C() {
$arr = $undefined_var;
}
function fun_B() {
$arr = array( 2, 3, 4 );
fun_A($arr);
fun_C();
}
fun_B();
fun_C();
?>

0 comments on commit 847de28

Please sign in to comment.