<?php
$pinfo = pathinfo(__FILE__);
$cur_path = $pinfo['dirname'];

include_once($cur_path.'/Whatap.php');

error_log('Start Daemon');
$daemon_count = 0;

while(true){
	// start daemon transaction
	// whatap_begin_tx(string service_name)
	error_log('==== Start');
    Whatap::whatap_begin_tx("daemon_service");

	$start_memory = memory_get_usage();
	$start_memory1 = memory_get_usage(true);
	echo "start=".$start_memory.",start1=".$start_memory1."<br/>\n";

	// Start whatap_begin_spot(string, boolean);
	Whatap::whatap_begin_step("Test Whatap Set User Profile", true);

	for($i=0; $i<3; $i++) {
		echo "i=".$i."<br/>/n";
	}

	// End
	Whatap::whatap_end_step();

	//$db->close();
	$end_memory = memory_get_usage();
	$end_memory1 = memory_get_usage(true);
	echo "end=".$end_memory.",end1=".$end_memory1."<br/>\n";
	echo ($end_memory - $start_memory)."<br/>\n";
	echo ($end_memory1 - $start_memory1)."<br/>\n";

	sleep(1);
	
	error_log('==== End');
	// end daemon transaction
    Whatap::whatap_end_tx();

	if($daemon_count > 50){
		break;
	}
	$daemon_count++;
	
	sleep(5);
}

error_log('End Daemon');
?>
