demenvil / phpdesktop

Automatically exported from code.google.com/p/phpdesktop
1 stars 0 forks source link

A way to launch external processes/servers during startup or later, and automatic shutdown of these processes when app exits #163

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
User can execute applications using php's system() command or similar, but 
there is no easy way to end long running processes when phpdesktop application 
closes.

Use case 1
----------
User wants to run node.js server along with phpdesktop. That server should 
start when phpdesktop starts and shut down automatically when phpdesktop app 
exits.

Solution: In settings.json add option "startup_processes" which would be a list 
of .exe, allowed would be relative paths (phpdesktop dir) or full paths.

Use case 2
----------
While app runs user wants to run an external process. Currently this can be 
done using XMLHttpRequest to a php script that calls php's system() command or 
similar. Unfortunately there is no easy way to end this process when phpdesktop 
app exits. For example this process runs a long task, but user exits 
application early, so this process should be killed.

Solution: Add new function to JavascriptApi: LaunchProcess(). It should have 
some options whether the app window should be hidden. Use the ShellExecuteEx 
function and save process handle (SHELLEXECUTEINFO.hProcess) for later to end 
the process when app exits.

ShellExecuteEx: 
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762154(v=vs.85).aspx

SHELLEXECUTEINFO: 
https://msdn.microsoft.com/en-us/library/windows/desktop/bb759784(v=vs.85).aspx

Original issue reported on code.google.com by czarek.t...@gmail.com on 7 Mar 2015 at 8:34

GoogleCodeExporter commented 9 years ago
It is possible to close external processes currently, but only with some 
additional .bat script and WMI queries. This has been explained here: 
https://groups.google.com/d/msg/phpdesktop/PLC0dMz0Pp8/6kCC_VNTP_wJ

Such .bat script would check whether phpdesktop.exe process still runs and when 
it's not running anymore it could end external processes launched by php's 
system() command. It's a bit complicated, but feasible. Your app's processes 
names shold be unique to make it reliable.

Original comment by czarek.t...@gmail.com on 7 Mar 2015 at 8:43