Re: PHP running exec() Windows program very slow in comparison to UNIX equivalent program
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Wed, 06 Feb 2008 13:30:26 -0500
Otis wrote:
>> 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.
Good. That bypasses your problem, anyway. But what about next time? In this case I'd be interested in determining just why the delay is occurring.
For instance - as I said, try running it from a command line prompt with the same parameters. How long does it take?
Also do something like write the start time to a file at the start of the module and the end time just before it finishes. Do the same just before and after the exec() call (they can even be the same file if you close the file in PHP first). Such a time lag should be very noticeable.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.
- References:
- PHP running exec() Windows program very slow in comparison to UNIX equivalent program
- From: Otis
- Re: PHP running exec() Windows program very slow in comparison to UNIX equivalent program
- From: Jerry Stuckle
- Re: PHP running exec() Windows program very slow in comparison to UNIX equivalent program
- From: Otis
- Re: PHP running exec() Windows program very slow in comparison to UNIX equivalent program
- From: Jerry Stuckle
- Re: PHP running exec() Windows program very slow in comparison to UNIX equivalent program
- From: Otis
- PHP running exec() Windows program very slow in comparison to UNIX equivalent program
- Prev by Date: Re: Compile PHP for adding MySQLi module
- Next by Date: Re: Compile PHP for adding MySQLi module
- Previous by thread: Re: PHP running exec() Windows program very slow in comparison to UNIX equivalent program
- Next by thread: Re: PHP running exec() Windows program very slow in comparison to UNIX equivalent program
- Index(es):
Relevant Pages
|