Click to See Complete Forum and Search --> : PHP reentrancy


Anon
05-16-2001, 03:05 PM
Aarg!
I don't think there's a good solution to this so I'm going
to vent a bit (I'm a mild mannered venter), but if you see something I'm missing, please let me know.
The basics: I'm running Win98, Apache, PHP 4.05, Curl.
So unfortunately, passthru, exec, and backticks are pretty well broken in PHP and scheduled to fixed in PHP 4.06 (hurrah!).

I have a server page, call it Server.php and a straightforward dosbox php program, call it Munger.php
When Munger.php is called (via php -q Munger.php arguments...) it uses Curl (a most excellent program) to grab some pages (real time) and extract some info from them, then take action. Works great. Server.php pops up a web page for the client, gets some information via a form, and then wants to return a status page to the client. This page is happy, too, except for one thing.
In one case, as the very last measure before tidying up, Server.php must call out to Munger.php and it must do it right away. No dilly dallying, since munger.php must get to work right away. However, munger.php might be at its task for quite a while (several minutes, even though it must start quickly), and Server.php is not inlined to wait, nor does it need any feedback from Munger.php
Ideas. 1) Rewrite Munger.php to not exit by using die. But even if I do this, I tie Server.php to Munger.php and must wait for the output.
2) Invoke passthru, backticks, or exec. Even if they weren't broken (and yes I am using complete paths), passthru and backticks are out (as I understand) since they create a separate shell which Server.php would definitely wait for. But this still didn't work, even for a nice little .exe test file.
3) This may be useful to some since it at least allows running a standard .exe file: I open an Excel COM object, create a VB function within a workbook whose only function is to Exec the string that I pass it (via $Excel->Run (MyVBExecFunction, StrToExec)). It might be wedged but it works.
Unfortunatley, all bets seem to be off on reinvoking php while Server.php is still processing (I.e. with php -q Munger.php arguments ...). It doesn't give me an error (but maybe that is because Excel is the one doing the Exec-ing), but I don't get any output either.
4) My other idea on this was to use 3) to invoke the
windows scheduler to run Munger.php at the next available point in time, but it only seems to do the scheduling on the minute, and Munger.php does not have that kind of time to burn.

So, being out of clever tricks, my issue is with PHP not being reentrant. Maybe someone will tell me that I'm wrong.

Csaba Gabor

ame12
05-16-2001, 07:53 PM
I think I understand what you are saying... couple of questions: haven't tried to automate anything in PHP, but are you closing the COM connection to Excel? If so, try NOT doing that. Leave the Excel connection open after finishing your automation task.

Also, if worse comes to worse, you can try serializing access to the COM server using fopen and flock (trying to grab a file lock on some shared file). You can retry over some number of seconds using sleep until you either get access or give up.

Dave

===========================================
http://badblue.com/helpphp.htm
Free small footprint web server for Windows
P2P file-sharing, PHP, wireless apps & more
===========================================

ame12
05-16-2001, 07:55 PM
I also forgot to mention that it's almost certainly not reentrancy of PHP that's an issue. Might be just COM support (somewhat likely) or even multithreaded Excel automation support (probably equally likely, depending upon operation).

Dave


===========================================
http://badblue.com/helpphp.htm
Free small footprint web server for Windows
P2P file-sharing, PHP, wireless apps & more
===========================================

Anon
05-17-2001, 08:50 PM
Dave,
Thanks for your comments. I have a solution, and it is enough to make your stomach turn. Any person harping on Windows need not look further than this.

You are right about PHP being reentrant. Obviously, since there are lots of PHP sites getting tons of hits. My problem is that I can't invoke php directly while its running my page. Idea. Why don't I have my friend CURL request my php page, thereby causing php to process it. The result was weird. I tell Excel to Shell the command, and in the DOS box that gets generated, it looks like CURL runs (i.e. the DOS version, not the one in PHP), only it ignores the directive that I give it to put its results in a file. I suspect that curl is not reading the supplied arguments from the arguments file that I supply (though why this should be the case I haven't the foggiest). But even if this had worked, I still have the problem that Excel leaves the Shell Dos Box lying around. I've never been able to figure out how to close the thing (especially keeping in mind that there might be other DOSes with the same title bar floating around). By this point, I am mighty frustrated. Why is it that there isn't any way to start off an asynchronous (DOS) process which will kill itself when done? Is this too much to ask?
So there is this obscure command in Excel's VBA language called ExecuteExcel4Macro. And perhaps even more obscure than that is the excel Macro command, EXEC, which executes asynchronously and if you give it a DOS command, will kill itself when done, even if Excel is closed down by then. It's literally been years since I've used this guy so I had forgotten this nice little feature. I still can't call php.exe using this EXEC fella', but I pass it
"curl.exe -K curlArguments.fil" and it does the trick.
Meanwhile, I revised Munger.php (the object .php file that I desired to run) to be callable in any of three fashions: either through a direct (DOS) invokation of php.exe (I check $argv[0] containing Munger.php) or via a web page (I check argc <= 1 and at least one variable has to be passed in.) In both of these cases, I put the passed in variables into an array, and pass them into the Munger function. The third calling fashion is to have the file be included, in which case I don't want the top few lines of code calling the Munger function and the caller (includer) will be directly responsible for calling the Munger function.

Regards from the land of obscurity,
Csaba Gabor