15 Sep

PHP and Memcached Returning Random Data

This took a long time to track down and only applies in specific circumstances:

  • Your process is forking
  • You are using persistent memcache connections
  • The data you request does not match what you receive, for instance you expect an array and an integer is returned.

The problem is caused by the persistent connection being shared after the process has forked. This is a known issue on database connections which is why you should always stop and restart your database connections after a process forks however this is not a documented ‘feature’ of the memcache connections. Trying to close and reopen the memcache connections doesn’t help either.… Read the rest

12 Sep

Jquery Save to Excel II

Slightly more advanced version of my previous script. This script handles if the table doesn’t have an ID which was a problem previously. It also paves the way for multiple export options including Excel, HTML and PDF – whatever your server can handle.

This code is slightly different to previous code as it will add the export buttons to all tables on the page that do not have a class of ‘noExcel’. Run this script from your jQuery ready() function. A simpler version of this code is available at http://www.topsemtips.com/2008/11/save-html-table-to-excel-using-jquery/:

var RandomIDToUse = 1000;
function AddActionsToTable(  )
{
$(" table:not(.noExcel)").each( function(i){
var TableID = this.id ;

if ( $(this).data('ToolBarAdded') === undefined) {
$(this).data('ToolBarAdded',1);
var TableName = this.id ;
if ( this.id == '' || this.id === undefined ){
TableName = "MyRandomID" + RandomIDToUse ;
$(this).attr('id',TableName);
RandomIDToUse++ ;
}
var FormID = 'form' + TableName ;
var SavetoID = 'saveto' + TableName ;
var DataToDisplayName = "datatodisplay" + TableName ;
var SaveToDisk =
"<div class='TableToolBar'>" +
"<form action='/reports/SaveData/SaveToExcel.php' method='post' target='_blank' id='" + FormID + "'" +
"onsubmit='$(\".DataToDisplay\", this ).val( $(\"<div>\").append( $(\"#" + TableName + "\").eq(0).clone() ).html() )'>" +
"<input type='hidden' id='" + DataToDisplayName + "' name='DataToDisplay' class='DataToDisplay' />" +
"<input type='hidden' id='" + SavetoID + "' name='SaveTo' val='' />" +
"</form>" +
"<input  type='image' src='/images/icons/page_excel.png' width='16' height='16' alt='Save to Excel' title='Save to Excel'" +
" onclick='$(\"input:checked\").attr(\"checked\",true); $(\"#" + SavetoID + "\").val(\"Excel\"); $(\"#" + FormID + "\").submit();' />" +
"  " +
"<input  type='image' src='/images/icons/doc_table.png' width='16' height='16' alt='Save to HTML' title='Save to HTML'" +
" onclick='$(\"input:checked\").attr(\"checked\",true); $(\"#" + SavetoID + "\").val(\"HTML\"); $(\"#" + FormID + "\").submit();' />" +
"  " +
"<input  type='image' src='/images/icons/doc_pdf.png' width='16' height='16' alt='Save to PDF' title='Save to PDF'" +
" onclick='$(\"input:checked\").attr(\"checked\",true); $(\"#" + SavetoID + "\").val(\"PDF\"); $(\"#" + FormID + "\").submit();' />" +
"</div>" ;
$(this).after( SaveToDisk ) ;
}
} ) ;

}
12 Sep

PHP Processes Getting Killed

This one took a while to suss out.

Symptoms are:

  • Database connections idle for long periods of time.
  • Processes start and then stop intermittently.
  • Processes report ‘Killed’ when you run them.
  • Running ‘dmesg’ from the command line shows the OMM process was called.

If this is happening to you you need to check your logs to see if the OMM (out of memory manager) is getting called. To check this run ‘dmesg’ from a Unix command line and look for the term ‘OMM’. The OM process kicks in when there is not enough memory to satisfy memory requests (malloc) that the system has already OKed.… Read the rest