Hi,

I am running wamp on windows server 2003 for a while now, and I haven't had any major issues until now.

I was revamping some code, and I came across a mind boggling issue relating to executing system commands.

What is happening, is I have a file uploader, that takes a user's file and processes it, then starts a fork (using popen("start /b php.exe file.php uploaded.fiile", "r") )
which takes it's time processing the file.

It was all working fine until today, I updated major portions of code and things went downhill from there.
Every time I would upload a file, the page would hang and I would not be able to navigate to any page on the site until the PHPSESSID cookie was cleared.
I narrowed it down to popen, and tested it with exec and system as well.. all causing this behavior.

I then came accross the following bug report which best describes the behavior I am experiencing:
http://bugs.php.net/bug.php?id=22526

However, that is very old and I am running the latest version of wamp including php 5.2.6 and apache 2.2.8

Unfortunately, The suggested 'hack' of using session_write_close didn't work, although it did prevent me from having to clear my session, I just caused the page calling popen to hang, rather than my whole session.

Now I don't know if this has any significance, but I noticed that if I restart apache i can run simple system commands until I upload a file, then it all reverts to the phenomenon as I described above.

I use apc to monitor the upload progress, so I that might be contributing to the issue. What really gets me though, is how I was running the script fine earlier with no issues.

If anyone has an idea of what might be causing this behavior please let me know, and meanwhile, if there is a method of forking off a php thread on windows that does not require executing a system command it would be greatly appreciated.

Thanks

    I really hope I have an answer to your prob vs spamdexing your post 🙂

    A while back I had a file which posted an action to a hidden iframe. The iframe page did a long process and updated the parent window through a bit o javascript. OK, fine. But next I wanted a way to stop the process @a certain point. So I made a button which sent a query to another hidden iframe (ajax people forgive me but iframes aren't going away 🙂, which also did a session_start().

    I found out that it didn't work because the session file was locked in one way from the first file. What finally worked is to have teh second query write on/off to a 2nd file besides the session file (I hope this makes sense), the file had a name containing the same session id. the process/page in the first iframe would read the 2nd file and if it was written as "off", would stop the process successfully. But trying to call session on the 2nd iframe process gave me trobles.

    this was over a year ago - wish I could be mor precise but think this MIGHT help you out and let me know if it does.

    Samuel

      Hi sfullman,

      Thanks for the reply.. I have finally figured out a way to prevent this behavior from happening.

      First let me explain all the things I tried, just incase someone else happens to be suffering from the same issue.

      The following is the scenario which causes popen to hang the session:

      I have an upload page, which posts a file to process.php. As the file is uploading, through a hidden iframe, I am polling the progress through the use of ajax. In my ajax callback php file, I am including my fileuploader.php, which contains the fileuploader class.

      I then call a static method that checks the apc cache for the upload status, then writes it to a session variable, and returns. This information (from the session variable) is then relayed back to the upload page.

      Once the uploading of the file is complete, process.php then creates a fileuploader object and calls the CompleteUpload method, which moves uploaded file to the appropriate location, etc.. then starts a thread via popen which processes the uploaded file from the new location.

      It seems that once this popen command is executed, the current session hangs. I cannot view any page which uses sessions (however, if there is a page which does not use sessions at all, it is viewable).

      Now this is where it gets kind of interesting. If I create a new file, lets call it test.php, and have a popen('start /b foo.exe', 'r'); it will run fine indefinetly without causing any problems. However, once the phenomenon is triggered via my upload script, that page will hang as well (even if it does not have any session handling). The file will only run again once apache is restarted.

      I also logged into my server via RDP, and opened process explorer. When this behaviour occurs, there are child processes "cmd.exe and php.exe" listed under httpd.exe, but they are hanging, they have no PID, no information, nothing. And if I try to view their properties with process explorer, it crashes !

      I then went back to that bug report (http://bugs.php.net/bug.php?id=22526) and tried the 'quick hack' that was described there once again (by doing a session_write_close before executing popen) , and sure enough, it worked ! I had tried it earlier with no avail, but I realized that I had tried it AFTER the behaviour occured, and it seems like once its triggered, apache must be restarted for it to return to normal, or else all exec, popen, or system commands will fail.

      Althoug that thread is relatively old (php 4 ) it seems this issue is still there with 5, just that the conditions must be right for it to occur ?

        Write a Reply...