Friday, 30 March 2007

PHP: Handling MySQL replication failure gracefully - Part 2

The first version of this code failed to work on 5.1 so here is a version that does:
$result = mysql_query("show slave status;");
$row = mysql_fetch_assoc($result);
if( ($row['Slave_IO_Running']!='Yes') || ($row['Slave_SQL_Running']!='Yes') )
$fp = fopen('tmp/halt', 'w+');
header('Location: index.php');

Remember to add something like:
if(file_exists('tmp/halt')) exit('Unable to complete request at this time');

at the start of your app execution so as to stop users entering data that can cause all kinds of living nightmares when it comes to patching the data together.

No comments: