Jump to content

Recommended Posts

System:

[pre]  Windows XP Pro

  Service Pack 3 / .Net 3.5

  Apache 2.2.11

  PHP 5.2.9-2[/pre]

 

Hi,

  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:

ini_set("max_execution_time", "240");

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:

exec($command);
exec($command . " >NUL");
exec("start /B " . $command);
shell_exec($command);
pclose(popen("start ". $command, "r"));

$output = array();
$result = null;
$return = exec($command, $output, $result);
or
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\lc.workspace.com\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.

Sébastien.

lol, yeah, even `ping xxx` is slow thru php on a web server, but yeah thru the command line it is very speedy.. idk if there is any way to speed up commands thru a web server. but if anybody here has any clues I'd sure love to know aswell

lol, yeah, even `ping xxx` is slow thru php on a web server, but yeah thru the command line it is very speedy.. idk if there is any way to speed up commands thru a web server. but if anybody here has any clues I'd sure love to know aswell

Actually, for converting mathematical formula into .png file, I have to use latex.exe to compile the .tex file and create the .dvi file. Then, I have to use dvips.exe to convert the .dvi file into a postscript file. Finally, I have to convert the .ps file into a .png file with Imagick (convert.exe). Optionally, I can use identify.exe (Part of Imagick too) to get some info about the file and to see if it is not corrupted.

 

The only program I have difficulties with is latex.exe and dvips.exe... the rest runs fine.

A little update here.

 

After many trials and fails, I've decided to make a little test environnement and installed EasyPHP 3.0. Just to see what would happen. Guess what, everything works perfectly. Good, so i'm on the right path.

 

I've started by comparing EasyPHP config files (httpd.conf and php.ini) with the original ones I was using with a file compare tool. The weird thing is that they are virtually identical (except for some variables EasyPHP use like the $path thing).

 

I've retested with the version of Apache and PHP that EasyPHP uses. Same problem occurs even with an identical php.ini and httpd.conf. So there must be a thing EasyPHP do that I don't !

 

Now, I know it's possible to make this to work because it work in EasyPHP. But I can't figure out what is different.

 

Does that help somebody to help me ?

 

Thanks

Sébastien

Ok, I've seen a bunch of bug report similar to my problem on PHP.net. But it seems that PHP Team and Apache Team are throwing out the ball at each other. PHP Team say it's an Apache problem and Apache Team say it's a PHP problem!

 

Anyway, I've tried with a COM object but it is still the same result, the process just hang for more than 2 minutes.

 

Now, I was wondering what EasyPHP was doing that i'm not. Because with a 100% identical configuration files (PHP and Apache), the problem does not occurs using EasyPHP. I discovered that EasyPHP does not start Apache in Service Mode. So, I reinstalled PHP and Apache and I have made Apache start as a console application. And guess what ? The problem just vanished. The problem seems to be when Apache is started as a Windows Service. Now I have this annoying cmd.exe window in my task bar but at least, everything works according to my needs. I will probably reply on some PHP bug reports to tell them my findings. Could help someone else ! Who knows?

 

Thank all of you very much for your help. I think i've tried everything on that one !

Thanks again.

 

Sébastien.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.