I need to build a system that a user will send file to the server
then php will run a command-line tool using system() ( example tool.exe userfile )
i need a way to see the pid of the process to know the user that have start the tool
and a way to know when the tool have stop .
Is this possible on a Windows vista Machine , I can’t move to a Linux Server .
besides that the code must continue run when the user close the browser windows
Rather than trying to obtain the ID of a process and monitor how long it runs, I think that what you want to do is have a "wrapper" process that handles pre/post-processing, such as logging or database manipulation.
The first step to the is to create an asynchronous process, that will run independently of the parent and allow it to be started by a call to a web page.
To do this on Windows, we use WshShell:
…and (for completeness) if we want to do it on *nix, we append
> /dev/null 2>&1 &to the command:So, now you know how to start an external process that will not block your script, and will continue execution after your script has finished. But this doesn’t complete the picture – because you want to track the start and end times of the external process. This is quite simple – we just wrap it in a little PHP script, which we shall call…
wrapper.php
So instead of executing the tool directly, we make our command in the main script:
…and we should have a finely controllable solution for what you want to do.
N.B. Don’t forget to
escapeshellarg()where necessary!