Blog of Death
ASpell Dictionary Problem on Win32 w/ Workaround
March 26th, 2005
Found a problem with ASpell Win32 / PHP 5.0.3 (Related: see my article about Enabling pspell on Win32).I found that pspell_new() fails to initialize the first time after the PHP script loads, saying that it can't find the dictionary files. This is actually intermittent - the odd time it will successfully initialize and spellcheck text correctly. So it looks more like a bug with either the pspell extension or the ASpell libs (or something in between the two).
Anyway, I found the easiest way to work around the problem is simply trying again in the script. I set up a simple loop to try it up to three times before failing:
[code]
$pspell_worked = FALSE;
for ($i=1; $i <= 3; $i++)
{
if (($pspell_link = pspell_new("en")) !== FALSE)
{
$pspell_worked = TRUE;
break;
}
}
if (!$pspell_worked) die("Could not initialize ASpell Library.");
// If you got here, it worked!
// Continue with pspell_check() and so on...
[/code]
I have my test copy set up to log the number of tries it takes to initialize PSpell, and it very consistently reports 2 tries with the second try being successful. Never has it reached 3, but occasionally it reported success on the first try. Sounds a little bit like the Holy Hand Grenade doesn't it?
Doing this will of course add a little bit of a delay to starting up your spellchecking application, but it's not too terrible overall. It may make a difference under a heavy load scenario though, so I leave it up to you to determine the scaleability of this workaround.
Permalink
http://www.oblius.com/blog/view.php?ID=1b61f88aa319a6d09b0d9d9c3ac61313
