Archive for the ‘PHP’ Category

Re: Boost performance with parallel processing

Saturday, January 31st, 2009

Martin Roest posted an article about parallel processing. Here’s a more reusable version of the code, OOP style:

Usage with callback function:

< ?php
$pc = new ProcessController(10);
$pc->process($documents, 'processDocument');
?>

It supports static method callbacks:

$pc->process($documents, array('DocumentProcessor', 'processDocument'));

And callbacks on an instance of an object:

$pc->process($documents, array($documentProcessor, 'processDocument'));

(more…)

Redirect After Post, But Not On Failure

Saturday, January 10th, 2009

Post/Redirect/Get (PRG) is a great practice, but don’t use it when the post is a failure. Here are some reasons:

  • If post failed because of non-validation issue, e.g. if “try again later” was the result, then the client only has to refresh the page to submit the post again.
  • It’s more efficient (greener) and easier to develop: if redirecting even on failure, then you must store the post data in the session and pull it back out to refill the form (or require the user to fill out the entire form again).

Implementation examples follow:

(more…)