Zend - The PHP Company




External

Add Code


Execute and terminate background processes in Windows  

Type: code fragment
Added by: chnuschti
Entered: 30/08/2004
Last modified: 09/12/2003
Rating: - (fewer than 3 votes)
Views: 8340
Execute AND terminate background processes in Windows whilst your PHP-Script continues to execute. This code fragment is useful if you want to execute AND terminate a background process (that can be invoked via commandline) in Windows OS using PHP, without having your script hanging. The problem with the given functions of PHP for this purpose (exec(), passthru(), backtick-operators etc.) is, your script will hang if you launch a process that should run whilst your script is continuing to execute (e.g. services). To terminate the process you'll need the utility "pskill". Not a big thing, but I hope it helps you, as I wasted a lot of time on this theme until i got a working solution. It was tested only "local" on Windows 2000, Apache 1.3 and PHP 5.0. Read the original contribution at: http://php3.de/manual/de/function.exec.php download pskill at: http://www.sysinternals.com/ntw2k/freeware/pskill.shtml


<?php
//start background process (e.g. tlswrap) minimized in the background:
$WshShell = new COM("WScript.Shell");
$oExec $WshShell->Run('X:\programs\tlswrap\tlswrap.exe -c 20 -C ALL -h 127.0.0.1 -l 7000'7false);

//terminate process with pskill-utility
$WshShell = new COM("WScript.Shell");
$oExec $WshShell->Run('X:\programs\pskill\pskill.exe tlswrap.exe'7false);
?>


Usage Example




Rate This Script





Search



This Category All Categories