Monday, June 29, 2009

PHP 500 Internal Server Error

Today I encountered an error message in the integration test with "500 Internal Server Error". I have wasted an hour in searching the "Client-Warning: Redirect loop detected" in google and playing around with the require statement etc.

The easiest way should be just turning on the error logging in php.ini, log_error = On. The error message in the log told me the require statement couldn't find the target php file. That's it...

PHP Fatal error:  require_once() [function.require]: Failed opening required 'utilities.php' (include_path='/opt/ecloud/i686_Linux/php/lib/php') in /opt/ecloud/i686_Linux/apache/htdocs/accelerator/evalPhp.php(18) : eval()'d code on line 2

Friday, June 26, 2009

Jetty Handler with NIO and Continuation

After getting the http or https request through SelectChannelConnector or SslSelectChannelConnector, the custom handler method that you extend from AbstractHandler handle(...) will run.
public void handle(String target,
HttpServletRequest request,
HttpServletResponse response,
int dispatch)
throws IOException,
ServletException {

// Obtain Jetty continuation
Continuation continuation = getContinuation(request, null);

// Create a custom callback and store it in each HttpServletRequest
// This callback is to wrap the continuation object for the other thread
// to call continuation.resume() for generating the response.
// "callback" should be a final static variable in production server.
Callback callback = (Callback) request.getAttribute("callback");
if (callback == null) {
callback = new Callback(continuation);
request.setAttribute("callback", callback);
}

// Synchronize on callback to prevent continuation.resume() from
// happening before continuation.suspend().
synchronized (callback) {
if (continuation.isNew()) {
// Dispatch the request to another area with different thread
// and of course, callback must be referenced later to call
// continuation.setObject() and continuation.resume() down the road.
}
// zero here for the simplicity
continuation.suspend(0);
}

// Up to this point, the continuation is resumed, and got the object ready
// for response.
PrintWriter out = null;
try {
out = response.getWriter();
Object obj = continuation.getObject();
// further processing the obj for the "out"
} finally {
if (out != null) {
out.close();
}

// Reset the continuation
continuation.reset();
continuation.setObject(null);
}
}

Wednesday, June 24, 2009

MySQL alter table with multiple indexes

Recently I need to add/delete multiple indexes in the same table. I didn't notice that, I can chain the add/drop index in a single "ALTER TABLE" which only does one table copying once instead of multiple times.

http://brian.moonspot.net/mysql-alter-multiple-things

In the past, I tried to copy over the huge dataset to a temp table with the new indexes created, but I encountered a problem in deleting a FK in the child table that I can't solve. http://bugs.mysql.com/bug.php?id=14347