jargen Posted February 17, 2012 Share Posted February 17, 2012 I need a way to start a program and store the PID, then manage to stop it at the users request later. Im not sure how i would go about this. It has to work on Windows, Any help? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/257200-start-and-stop-a-program/ Share on other sites More sharing options...
scootstah Posted February 17, 2012 Share Posted February 17, 2012 Take a look at system() or exec() Quote Link to comment https://forums.phpfreaks.com/topic/257200-start-and-stop-a-program/#findComment-1318405 Share on other sites More sharing options...
jargen Posted February 17, 2012 Author Share Posted February 17, 2012 Take a look at system() or exec() Dosent help work out how to get the Process ID and stop it. Quote Link to comment https://forums.phpfreaks.com/topic/257200-start-and-stop-a-program/#findComment-1318436 Share on other sites More sharing options...
kicken Posted February 18, 2012 Share Posted February 18, 2012 PHP doesn't have any way to execute something in the background, which is what you need if you want to launch something then get the PID. In Linux/Unix you can do this using a simple shell script, such as: #!/bin/bash /usr/bin/php -r 'sleep(100);' >/dev/null >&1 & disown echo $! And run it: if (exec('./go.sh', $output, $ret)){ echo 'Launch successful. Pid='.$output[0]; } else { echo 'Launch failed'; } For windows, running in PHP would be essentially the same but you would have to find or create a program to use as an intermediary which will launch the program you want in the background, then output it's PID. Quote Link to comment https://forums.phpfreaks.com/topic/257200-start-and-stop-a-program/#findComment-1318525 Share on other sites More sharing options...
requinix Posted February 18, 2012 Share Posted February 18, 2012 I don't suppose this thing you're running has a daemon mode, right? Quote Link to comment https://forums.phpfreaks.com/topic/257200-start-and-stop-a-program/#findComment-1318533 Share on other sites More sharing options...
jargen Posted February 18, 2012 Author Share Posted February 18, 2012 I don't suppose this thing you're running has a daemon mode, right? ...I have no idea Quote Link to comment https://forums.phpfreaks.com/topic/257200-start-and-stop-a-program/#findComment-1318681 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.