why is using wine from apache/php is much slower than cli ?

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
fourchu
Newbie
Newbie
Posts: 4
Joined: Mon Nov 25, 2013 10:00 am

why is using wine from apache/php is much slower than cli ?

Post by fourchu »

I want to use a windows command line tool from a php script in linux.
The app is some sort of obscure proprietary keygen that returns results to stdout.

I am using Ubuntu 12.04.3 Server 32bits, wine version 1.4 and xvfb
I operate my server with ssh only. Honnestly i do not care about display, i used xvfb as some posts mentionned xvfb was suitable for a server witout screen. all i want is the stdout of tool.exe


www-data home directory is /home/www-data (some .wine directory got created by wine there)

here is the php code sample i am using

Code: Select all

<?php

function executeCmd($cmd) {
    $output = array();
    $return_var = 0;
    exec( $cmd , $output , $return_var );
    if ($return_var != 0) { 
        $msg = "Error: " . $output[0];
        error_log($msg);
        die($msg);
    }
    $res = @implode("\n", $output);
    return $res;
}



echo '<pre>';

$serial = @$_GET['serial'];
$mac    = @$_GET['mac'];

$cmd = "export DISPLAY=':1' ;  /usr/bin/time -p wine /var/www/tool.exe $serial $mac 2>&1";

var_dump( $cmd );

$start = microtime(true); 
$response = executeCmd($cmd);
$end = microtime(true); 

$time = $end - $start;
var_dump("$response");
var_dump("TIME=$time");

?>
xvfb is started with command:

Code: Select all

Xvfb :1 >>/var/log/xvfb.log  2>&1  &
in etc/rc.local

a typical response is

Code: Select all

 string(103) "export DISPLAY=':1' ;  /usr/bin/time -p wine /var/www/tool.exe K252045594 AAEE5D688BC1 2>&1"
string(20) "TIME=5.2689480781555"
string(172) "
Key generator v2.53 

S/N=K252045594 
MAC=AAEE5D688BC1 

key=58482622ZESFD

real 0.52
user 0.00
sys 0.00"

What i do not understand is that the line exec($cmd) takes about 5 seconds VERSUS if i use the same command line from bash, i get a response in a typical 0.5seconds
besides, the output seems to say more or less the same, it seems some resources taken by wine take some time to close. I do not know, i am new to wine.

What am i doing wrong ?
How do i configure wine to get with php the typical 0.5sec response time instead of the observed 5 seconds ?

any hint is appreciated

fourchu

ps : i tried to wineconsole instead of wine but i get error message : "fixme:event:wait_for_withdrawn_state window 0x10056/200001 wait timed out"
oiaohm
Level 8
Level 8
Posts: 1020
Joined: Fri Feb 29, 2008 2:54 am

Re: why is using wine from apache/php is much slower than cl

Post by oiaohm »

https://bugs.php.net/bug.php?id=48403 fourchu issue isnot wine. Its PHP. PHP hates the exec command. exec command ends up with monster lag. Yes longer the program runs in php exec the the worse off you are.

In some cases its better to setup a decanted user and ssh from php than use the PHP exec options. Even sudo out of PHP exec can end up faster.
fourchu
Newbie
Newbie
Posts: 4
Joined: Mon Nov 25, 2013 10:00 am

Re: why is using wine from apache/php is much slower than cl

Post by fourchu »

i agree using php exec does imply a performance hit. typically 0.1 ~ 03sec to create the additionnal process and return status of a simple command such as "ls /" for instance

but not 5 seconds.

there must be something else
oiaohm
Level 8
Level 8
Posts: 1020
Joined: Fri Feb 29, 2008 2:54 am

Re: why is using wine from apache/php is much slower than cl

Post by oiaohm »

Commands executed via shell_exec() take a lot longer to run than when run directly from the Unix shell. In the example code below, a task that takes 0.5-0.7 seconds takes 5 seconds.

This effect is reliable, and a given task's "how much longer it takes than it should" ratio seems constant. In the simple case below, it takes 8-10 times longer than it should. For a specific more complex test case at our side, the task consistently takes 14 seconds from shell and 83 seconds from shell_exec()

This effect is apparently identical for the entire family of process-handling functions: passthru, exec, shell_exec, and popen all show the exact same "slowness multipliers" as described above.
fourchu when I go to a effort of providing a link to a very particular bug report it does pay to read it.

fourchu the PHP problem is how low priority the executable becomes when called from PHP. So larger the application worse the effect. So a 0.5 run executable expected outcome is 5 seconds.

Note the 14 seconds run ending up 83 seconds.

fourchu so its PHP being PHP. I have told you a way around it. Setup a ssh user and use php ssh libraries.

ls is simple so its expand is also small.
fourchu
Newbie
Newbie
Posts: 4
Joined: Mon Nov 25, 2013 10:00 am

Re: why is using wine from apache/php is much slower than cl

Post by fourchu »

ok. thanks for the reply. the post is interesting indeed

i keep observing that simple commands that are not wine do reply in an acceptable response time (ex: ls, openssl)

are you refering to something like

Code: Select all

<?php
$connection = ssh2_connect('localhost', 22);
ssh2_auth_password($connection, 'phpuser', 'password');

$stream = ssh2_exec($connection, 'wine tool.exe --help');
?>
(borrowed from http://php.net/manual/en/function.ssh2-exec.php)

in the mean time, since i had no problem with a simple sh script environnement, i made my own daemon listening to a redis list for incoming requests and having php push requests to that very redis list and later pull responses from redis too.

it's a bit crude, but it does the job.
oiaohm
Level 8
Level 8
Posts: 1020
Joined: Fri Feb 29, 2008 2:54 am

Re: why is using wine from apache/php is much slower than cl

Post by oiaohm »

fourchu wine is not a simple command. Wine is more in the class of imagemagick or other heavy user.

Yes simple commands under php are fine the multiplier is not bad.

fourchu your crude solution with polish is most likely more secure than the ssh one. Basically you have just found out an important limitation of PHP to remember. The performance limitation is also part Apache/webserver. To prevent scripts from being able to overload server. Yes a important consideration with your work around. Yes why I said ssh was the fact you could have the processing host and the web host split.
Locked