542 Part V . Advanced Performance The previous (Tomcat web server)

542 Part V . Advanced Performance The previous snippet calls the functions for querying the various replication servers. Again, by adding a feature to gather this data from a MySQL database, you could use one function and call the server based on what type it is as stored in your database. function slavestatus ($host,$username,$password) { $dbconn = mysql_connect($host,$username,$password) or die ( Cannot connect to database server ); $result = mysql_query( SHOW SLAVE STATUS ); $timeresult = mysql_query( SELECT NOW() ); $time = mysql_result($timeresult, 0, 0); The next step is to make a connection to the database and issue statements, including one that queries for the current time from the replication server. while ($status = mysql_fetch_array($result)) { $mysqlserver = $host; $file = $status[4]; $position = $status[5]; $run = $status[6]; $errnum = $status[9]; $errmsg = $status[10]; } Taking the results from SHOW SLAVE SERVER, I parse them into variables that make some sense for the application context. The code looks like this: if ($run != Yes ) { $color =
; $additional = $errnum - $errmsg

; } else { $color =
; } print $time

$color Slave

$color $host $file $position $run

$additio nal

n ; } The contents of the $run variable are examined. If it is anything other than Yesis found, the background color of the table cell changes to red (otherwise it s green). Pointing a Web browser to the page results in the listing illustrated in Figure 18-13. The replication status from Figure 18-13 is taken directly from output of the appropriate SHOW statement. Notice that there is no Yes or No applicable for the master server. This is because the master server doesn t know anything about replication or the slaves that replicate from it. It simply goes about its business of recording updates and changes to the binary replication log.
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

Leave a Reply