Re: PHP running exec() Windows program very slow in comparison to UNIX equivalent program



>> It's not easy - you need to create a PHP extension for it. Not hard once you've done it a few times, but the first couple of times will have you pulling your hair out. See php.net for details if you want to go that route.

I'm not sure I'm up to that just yet.

But here's what I did do.

After researching, I have made a small .dll file using VB6. It is called astro_php.dll. Currently, it simply calculates the longitude and speed of one given planet on one given day. The astro_php.dll is about 24k in size.

Then in my PHP script where I was previously calling exec(swetest . . . ), I have replaced this with:

Function Get_1_Planet_geo($jd, $p_idx)
{
unset($output,$long_speed);
$obj = new COM("astro_php.astro_php_cls");
$output=$obj->Get_1_Planet(strval($jd), strval($p_idx));
$long_speed = explode(',',$output);
return $long_speed;
}

The time to do 140 loops, as this is what the script does for this particular function, went from 5.5 seconds using swetest.exe and 11.5 seconds using a VB5 program I wrote to try to replace swetest.exe to:

60 millisec

BINGO!


The only thing I do not yet understand is why I must pass strings to the astro_php.dll function instead of doubles or integers. But with the speed gained above, who cares, right?

Now I have to work on replacing the loop that runs 562 times and takes a total of 22.6 seconds with the above and see how much time I save (I did this and it went from 22.6 seconds to less than a second, I think).

So, by converting a VB6 DLL into a COM and calling the COM from PHP I am able to work around the speed limitations of swetest.exe, PHP, and Windows.


Thanks to all for your help.




Allen





Jerry Stuckle wrote:
Otis wrote:
>> is this a compiled program (.exe) on Windows, also? What language?

Yes, compiled in C, I believe. Just for fun, I wrote a little program in VB5 that essentially does what this other compiled C Windows program does in just one of the loops that gets executed about 140 times (at about 38 msec a loop on Windows). To my astonishment, my little VB5 compiled program, which is only 22kbytes) took twice as long as the C .exe program to process the 140 loops, 11.5 secs versus 5.5 seocnds. I know for a fact that VB5 and VB6 compiled programs are very fast. My desktop program of the same application runs lots more calculations, through many more loops, in about 3 seconds total. So it is the interaction between PHP and the .exe on Windows that is slow. The same PHP script with a UNIX ".exe" runs in 4 to 5 seconds.


It doesn't surprise me that the VBScript takes less time; C is a very efficient language. Other high-level compiled languages. while fast, can seldom meet the speed and memory footprint of a good C program.

Here is the line of code that runs so differently, time-wise:

exec ("swetest -bj$ejd -p$p_idx -fls", $out);

My PHPEd profiler shows this line of code to be the time hog.


I would expect that. Your profiler is going to consider that LOC being executed from the time you call it until the executable returns.


>> No reason in PHP why it should do that. There is very little overhead in PHP for calling exec() in either Windows or Unix.

Then it is the way swetest.exe compiled in C is running on a Windows machine versus the way a UNIX compiled version of swetest is running on a UNIX server.


You'll have a lot of interaction with the OS at this point. PHP has to call the OS to load and execute the program. Of course, part of this process is checking security, loading shared libraries, etc. There's a lot of work which needs to be done to get a program started. Then there's more work to do to finish it.

However, this is quite excessive. I've executed Windows programs from PHP before without this big delay.

Of course, the other thing is how long it takes to to execute the program with those statements from a command prompt. This would more closely emulate what you're doing with exec().

>> Maybe look at why Windows is taking so long? For instance - does it have to load a bunch of DLL's, are you short of memory or other environmental considerations?

Any Windows program, either C or VB, loads run-time files of various sorts.
Obviously the VB run-time files are "worse" than the C files because my little VB program took twice as long to run 140 loops.

What I probably need to do is call the functions directory out of a libswe.a library (UNIX) or a swedll32.dll DLL (Windows). But I don't yet know how to do that using PHP. Do you have any ideas?

Thank you.


Otis



It's not easy - you need to create a PHP extension for it. Not hard once you've done it a few times, but the first couple of times will have you pulling your hair out. See php.net for details if you want to go that route.

.



Relevant Pages

  • Re: PHP running exec() Windows program very slow in comparison to UNIX equivalent program
    ... So, by converting a VB6 DLL into a COM and calling the COM from PHP I am able to work around the speed limitations of swetest.exe, PHP, and Windows. ... I wrote a little program in VB5 that essentially does what this other compiled C Windows program does in just one of the loops that gets executed about 140 times. ... the other thing is how long it takes to to execute the program with those statements from a command prompt. ...
    (alt.php)
  • RE: phpBB Worm
    ... the getpwent function is not supported on Windows. ... it probably depends on the web server ... I looked at the decoded Perl script, ... was invoked by PHP, which should have the Web server's permissions, ...
    (Bugtraq)
  • Re: Developing PHP under Windows - Why?
    ... Windows 2000, Apache 2, Microsoft SQL Server, and PHP. ... We went with the Windows route mainly for human resource reason. ... I knew virtually nothing about Linux at the time - and very little about Apache. ...
    (comp.lang.php)
  • Re: PHP / Sendmail / SMTP
    ... The problem is PHP! ... Then I am curious why anyone would need to use one on NIX? ... Windows is really only a single user system. ... at best its a one function server administered ...
    (comp.lang.php)
  • Re: PHP / Sendmail / SMTP
    ... As posted in my first message, why do i need sendmail on *nix while i don't need anything on windows to connect to a smtp server? ... Much PHP is hosted on large shared Linux machines, and teh ability of anyone to bypass any protection available from a common mail subsystem, and spew spam across the internet, is not a feature, its a bug. ... Then I am curious why anyone would need to use one on NIX? ... Windows is really only a single user system. ...
    (comp.lang.php)