note 73490 added to function.shell-exec

From: Date: Mon, 26 Feb 2007 05:07:04 +0000
Subject: note 73490 added to function.shell-exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-123866@lists.php.net to get a copy of this message
After many failed attempts to find a way to run a php script in the background (the script had to be activated from a web browser). Since I create and test my scripts on a windows box, I need an automatic way to detect if the script was running on windows or the Linux server. The activated script will continue to run even if you close your browser. <?php $runCommand = 'php -q FULLPATH/FILE.php'; if(isset($_SERVER['PWD'])//*nix (aka NOT windows) { $nullResult = $runCommand > /dev/null &; } else //windowz { $WshShell = new COM("WScript.Shell"); $oExec = $WshShell->Run($runCommand, 7, false); } ?> Also, to get the correct "basepath" from the script that runs in the background. try: <?php ignore_user_abort(true); set_time_limit(0); if(isset($_SERVER['PWD'])) { $basepath = $_SERVER['PWD']; } else { $basepath = ereg_replace('[^/]*$', '', $_SERVER['PHP_SELF']); } $extendedpath = '/path1/path2/'; $basepath = preg_replace("|(?:{$extendedpath})$|i",'',$basepath); echo 'Start In: '.$basepath; ?> Enjoy! Later, RayJ ---- Server IP: 69.147.83.197 Probable Submitter: 75.212.143.219 ---- Manual Page -- http://www.php.net/manual/en/function.shell-exec.php Edit -- https://master.php.net/note/edit/73490 Del: integrated -- https://master.php.net/note/delete/73490/integrated Del: useless -- https://master.php.net/note/delete/73490/useless Del: bad code -- https://master.php.net/note/delete/73490/bad+code Del: spam -- https://master.php.net/note/delete/73490/spam Del: non-english -- https://master.php.net/note/delete/73490/non-english Del: in docs -- https://master.php.net/note/delete/73490/in+docs Del: other reasons-- https://master.php.net/note/delete/73490 Reject -- https://master.php.net/note/reject/73490 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123866) next »