test two environments

I have a php health page that needs to verify php on PROD and DEV. right now its working in PROD but not DEV

<?php $companyenv = getenv("COEnvironment") ; .............. //errors $param = "display_errors"; if ($companyenv == "Dev") {$in = true;} else {$in = false;} $out = ini_get($param); "; ?>

Don’t know what you are asking for.

hello
need help with getting this php to work in two environments.
right now it works for my Production server but not my Dev servers. in the dev I suppressed the suppressed errors.

error_reporting = E_ALL
display_errors = Off
display_startup_errors = Off

display_errors NG bool(true) string(0) “”
display_startup_errors NG bool(true) string(0) “”

<?php $companyenv = getenv("COEnvironment") ; ................... //errors $param = "display_errors"; if ($companyenv == "Dev") {$in = true;} else {$in = false;} $out = ini_get($param); "; ?>

Since you felt the need to make a duplicate topic, I will give you a duplicate response,

I have a script that should run against 2 environments call Dev and Prod.
it checks the health of php.on each server.
see attach pic for results.
But I cant get it to work in both environments without breaking the other.


phpstuff.gif

What the full code that is going into that table? I am not seeing where those values are coming from, when you aren’t echoing anything out in the code posted.

<?php $starttime = microtime(true); require "/_private/connect.inc"; function showResult($testname, $expected, $got, $comments,$starttime) { $currenttime = microtime(true); $elapsed = intval(($currenttime - $starttime ) * 1000); if ($expected == $got) {$result = "OK";} else {$result = "NG";} //echo ""; //echo ""; echo ""; //echo "
Test Name Result Expected Value Returned Value
$testname $result "; var_dump($expected); echo " "; var_dump($got); echo " $comments
$elapsed
"; } function customError($errno, $errstr, $errFile, $errLine, $errContext) { $path = $_SERVER['PHP_SELF']; echo "Error: [$errno] $errstr
\n"; echo "File: $path Line: $errLine
\n"; } //set_error_handler("customError"); header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1. header('Pragma: no-cache'); // HTTP 1.0. header('Expires: 0'); // Proxies. ?> PHP Test .OK {color:green} .NG {color:red} .heading {font-weight:bold;} .comments {color:black;font-style:italic;}

PHP Test

<?php
$COenv = getenv("COLEnvironment") ;

echo "<table border=1>";
echo "<tr class=heading><td>Test Name</td><td>Result</td><td>Expected Value</td><td>Returned Value</td><td>Comments</td></tr>";
sqlsrv_configure('WarningsReturnAsErrors',1);
$conn = sqlsrv_connect($DBinstance01, $DBconst01);
$conn;
showResult("MSSQL Connect", true, $conn, "", $starttime);
if ($conn === true){
	//$conn===true
	$query = "SELECT TOP 3 RECID, FIELD1, FIELD2, FIELD3 FROM JOHNS_TEST_TABLE ORDER BY RECID DESC";
	$result = sqlsrv_query($conn, $query, array(), array( "Scrollable" => 'keyset' ));
	sqlsrv_errors();
	if ($result) {
		$numRows = sqlsrv_num_rows($result);
		sqlsrv_errors();
		showResult("MSSQL SELECT", 3, $numRows, "SELECT TOP 3...");
		if ($numRows > 0) {
			/*
			echo "<table border=1>";
			while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) {
				echo "<tr><td>" . $row['RECID'] . "</td>";
				echo "<td>" . $row['FIELD1'] . "</td>";
				echo "<td>" . $row['FIELD2'] . "</td>";
				echo "<td>" . $row['FIELD3']->format('n/j/Y g:i:s A') . "</td></tr>";
				//$sessiontestin = $row['RECID'];
				
				}
			echo "</table>";
			*/
			}
			
		}
	else {
		echo "<div class=NG>Query Failed</div>";
	}


	// Is an SQL insert needed to test? - probably not.
	/*
	$sql = "EXEC WEB.dbo.johns_test_table_insert ?, ?, ?";
	$params = array("phptest", "123", date('n/j/Y g:i:s A'));
	$result = sqlsrv_query($conn, $sql, $params);

	// INSERT SUCCESSFUL - NO ERRORS
	if ($result) {
		echo "<div class=good>Insert OK</div>";
		}
	else {
		echo "<div class=NG>Error: Insert Failed</div>";
		}
	*/	
	sqlsrv_close($conn);
}
else
{
	sqlsrv_errors(SQLSRV_ERR_WARNINGS);
}

$conn2 = oci_connect($OracleUser,$OraclePass,$OracleDB,'utf8');
if (!$conn2) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);

}

showResult("Oracle Connect", true, $conn2, "",$starttime);
oci_close($conn2);


//Sessions
$sessiontestin = date('n/j/Y g:i:s A');
$_SESSION['test'] = $sessiontestin;
$sessiontestout = $_SESSION['test'];
showResult("sessions", $sessiontestin, $sessiontestout, "current timestamp", $starttime);

//disable_functions
if ($COenv == "Dev") {$in = "get_defined_vars";}
else {$in = "phpinfo, get_defined_vars";}
$out = ini_get('disable_functions');
showResult("disable_functions", $in, $out, "",$starttime);

//errors
$param = "display_errors";
if ($COenv == "Dev") {$in = true;}
else {$in =  false;}
$out = ini_get($param);
//echo get_cfg_var("display_startup_errors");
showResult($param, $in, $out, "0 for Prod, 1 for Dev.  COLEnvironment is '$COenv'",$starttime);
$param = "display_startup_errors";
$out = ini_get($param);
showResult($param, $in, $out, "0 for Prod, 1 for Dev.  COLEnvironment is '$COenv'",$starttime);
echo "</table>";

?>

Tippet5x, going back to your original post, you talked about this code:
if ($companyenv == “Dev”) {$in = true;}
else {$in = false;}

Do you mean you want to know how to display different things based on these two results? If so, just do it in the same
manner as that code…

if($in==true) {
… Do code for Dev environment…
} else {
… Do code for Live environment…
}

Is that what you are asking for? We really do not understand what you want us to help you with. Hope that was it…

if ($COenv == “Dev”){$in = true;}
elseif
($COenv == “Prod”) {$in = false;}

?

Well, that just checks a string variable for values and sets a boolean variable to true or false. Therefore, it is really a waste
of code. Just use the original variable $COenv for compares. But, most likely it was meant so that the future code that
checks this value can do it this way: if ($in) {do some DEV code }else{ do some PROD code } …

So, still not sure what you are asking help with… In your original posts, you mentioned $companyenv, but, in other areas
you talked about $COenv… So your code posts are confusing…

please see the entire code on: July 13, 2016, 09:31:20 am post.

if I hit the web page on my productions servers everything is good (green)

if I hit the web page on my dev servers I get red (bad) I would like this to work just like the production servers.
see pic


Let’s just look at the last error for now…
[php]
$param = “display_errors”;
if ($COenv == “Dev”) {$in = true;}
else {$in = false;}
$out = ini_get($param);
showResult($param, $in, $out, “0 for Prod, 1 for Dev. COLEnvironment is ‘$COenv’”,$starttime);
$param = “display_startup_errors”;
$out = ini_get($param);
showResult($param, $in, $out, “0 for Prod, 1 for Dev. COLEnvironment is ‘$COenv’”,$starttime);
[/php]
PLEASE NOTE: I placed the code into the PHP tags are is required on this site. If you post large amounts of code as you
did earlier, please place them between the tags. This helps us copy the code into our program editors and saves time! TX

This code seems to set some parameters to pass to the showResult() function. The $in is the DEV/PROD value set before
in other code. The $out is the current setting in the PHP ini file for displaying errors. So, the code is doing exactly what you
requested it to do. I do not see at any point where your code actually sets the display-errors options in the PHP.ini file.

Now, to fix this there are two ways. You can set the display-errors options in the PROD server to be OFF and then lock them
so they can not be changed and set the DEV server to be ON. Then, you would never need to test for them. OR, you can add
code to set them depending on the enviroment variable ( $COenv = getenv(“COLEnvironment”) ; ) This is not a standard
PHP environment settings. Therefore, it must be set in the server somewhere. Are you sure this is set correctly in each of
the servers?

the PHP.ini settings were manually changed and the two environments are now the same.

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off

I was hoping to get the script to test the PHP health regardless of DEV or PROD.

So, why can you not do this? First, a DEV or PROD server is still just a server. You were using an environment variable to tell
which server is which. You were using $COenv = getenv(“COLEnvironment”) ; to get the value. But, if you want to do the same
tests for each server, why bother with this part.

If you want to turn on the error reporting for the DEV server, you can just put that in your config.php. Test to see which server is
running and set the error reporting to the correct settings.

Guess I am confused what you want us to help with.

Being confused on what is desired is why I haven’t added more to the conversation.

You can easily turn error reporting on for one and not the other. So the ‘health status’ has me confused.

Well, he is doing some sort of various lists of tests, but, I do not understand why he can’t tell which server he is on…
They must have different names and IP’s.

yes two different server with different ips.
I just want to test PHP regardless of the environment or server.

in the past the PHP setting were different but know that they are the same I would like to remove the variable of DEV under //errors and have it check php across the environment.


Untitled1.gif

Sponsor our Newsletter | Privacy Policy | Terms of Service