Asked  7 Months ago    Answers:  5   Viewed   45 times

The following PHP code does return me a runtime of about 3.5 seconds (measured multiple times and averaged):

$starttime = microtime(true);
exec('/usr/local/bin/convert 1.pdf -density 200 -quality 85% 1.jpg');
$endtime = microtime(true);
$time_taken = $endtime-$starttime;

When i run the same command over a ssh terminal, the runtime is reduced to about 0.6 seconds (measured with the command line tool time).

The version of the imagemagick library is

Version: ImageMagick 6.7.0-10 2012-12-18 Q16
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP

What could be the reason for this time difference?

One answer to a similar question here on stackoverflow was that the overhead comes from the Webserver having to start a thread/shell. Could this be really the reason? I thought threads are leightweight and don't take long at all to start/terminate.

Prior to calling exec i set the number of threads used by imagemagick (because this was/is a bug in OpenMP?, Reference) to 1 with exec('env MAGICK_THREAD_LIMIT=1');. The runtime from PHP does not change much, no matter what value i set for MAGICK_THREAD_LIMIT. Anyway there does not seem to be a bug in OpenMP on in this version because the runtime of the command line execution is ok.

Any suggestions of how i could improve the runtime of the above command would be greatly appreciated.

Thank you very much for your help.



When you log in to a Unix machine, either at the keyboard, or over ssh, you create a new instance of a shell. The shell is usually something like /bin/sh or /bin/bash. The shell allows you to execute commands.

When you use exec(), it also creates a new instance of a shell. That instance executes the commands you sent to it, and then exits.

When you create a new instance of a shell command, it has it's own environment variables. So if you do this:

exec('env MAGICK_THREAD_LIMIT=1');
exec('/usr/local/bin/convert 1.pdf -density 200 -quality 85% 1.jpg');

Then you create two shells, and the setting in the first shell never gets to the second shell. To get the environment variable into in the second shell, you need something like this:

exec('env MAGICK_THREAD_LIMIT=1; /usr/local/bin/convert 1.pdf -density 200 -quality 85% 1.jpg');

Now, if you think that the shell itself may be the problem, because it takes too long to make a shell, test it with something that you know takes almost no time:

$starttime = microtime(true);
exec('echo hi');
$endtime = microtime(true);
$time_taken = $endtime-$starttime;

At that point you know to try and find some way to make the shell instantiate faster.

Hope this helps!

Wednesday, March 31, 2021
answered 7 Months ago

Add 2>&1 to the end of your command to redirect errors from stderr to stdout. This should make it clear what's going wrong.

Wednesday, March 31, 2021
answered 7 Months ago

First of all, what is the version of PHP?

If other .php scripts work except for phpMyAdmin, the is pretty safe to assume something is wrong with phpMyAdmin installation. (either with the files or the Virtual Host)


  1. Can you run another script in phpMyAdmin directory? Try with a file containing phpinfo(); If it does not work then the problem is in your apache configuration.

  2. If the above is true, then the parser is not recognising phpMyAdmin/index.php as a php file, for some reason. Try reinstalling phpMyAdmin.


Remove AddType application/x-httpd-php .php. You should not need it.

In PHP 5.4 magic_quotes_gpc was removed. If you're running PHP5, remove that line.

As of PHP 4.0.3, track_vars is always turned on, so remove it also.

As of PHP 4.2.0, register_globals this directive defaults to off. In PHP5.3 register_globals is deprecated, as of PHP5.4 register_globals was removed. SO if running PHP > 4.2.0 remove that line.

Saturday, May 29, 2021
answered 5 Months ago

borrowed this shamely from here

Process process = new ProcessBuilder("C:\PathToExe\MyExe.exe","param1","param2").start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;

System.out.printf("Output of running %s is:", Arrays.toString(args));

while ((line = br.readLine()) != null) {

More information here

Other issues on how to pass commands here and here

Friday, June 4, 2021
answered 5 Months ago

You can implement your own test runner, for example by extending PHPUnit_TextUI_TestRunner and make it collect and print run times.

Friday, September 24, 2021
Stuart Blackler
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :