Windows XP Pro
Service Pack 3 / dotNet 3.5
Apache 2.2.11
PHP 5.2.9-2

In a website project I have to convert mathematical formulas into .png images with LaTeX in my PHP code. The problem I have is that when I call LaTeX from PHP, the program takes for ever to execute and PHP crash after the timeout have been reached.

And this, even if everything went normally without any error with latex.exe. However, in command line, this process takes a fraction of a second to execute without any error too.

My homework so far:

Like suggested in another forum, I have added this to my php file:
PHP Code:
to "remove" the timeout error. It worked. But the process takes 2 minutes 47 secondes to execute. This takes too much time since latex.exe can be called several times in a single page to generate multiple mathematical formulas. I have tried thoses commands, exec(), shell_exec(), popen()/pclose(), system(), all of them without any success. Here is some exemples I've tried:
PHP Code:
exec($command " >NUL");
exec("start /B " $command);
pclose(popen("start "$command"r"));
$output = array();
$result null;
$return exec($command$output$result);
exec('start /B "'.$command.'"'$output$return); 
and many other I don't remember. It's always the same result and latex.exe takes 2 min 40 sec or so to execute from PHP.

Once the timeout problem resolved, I don't have any error in the Apache logs.

In php.ini, safe_mode is Off and disable_functions is Off like suggested elsewhere.

I have tried some simple commands to test for permissions, like "dir *.*" and "copy from to"... Every things works fine, with the dir command, the folder is listed in the output array. With the copy command, the file is copied and I have the message "1 file(s) copied." in the array. All of these tests with other command went fine and took a fraction of a second to execute.

I had the idea to look what was going on in the windows task manager to see what is happening. It's weird, when I execute latex.exe through PHP, the processor usage goes up to 90% to 100% during 2 minutes 40 secondes or so, until the process stop and then everything comes back to normal. When I do the same command in command line, I can't even see the process in the task manager, it's too fast. And CPU usage doesn't even budge. This isn't normal?

I've tried to execute the PHP script directly from the command line (C:\WWW\\site>php index.php) and guess what !? Everything goes fine and latex.exe is executed in a fraction of a second. Could it be Apache blocking the execution of the program??

So here I am... I'm a bit lost now.

Thanks for your help and suggestions.