Re: Problem with EXEC and PASSTHRU

From: Date: Wed, 25 Oct 2006 13:12:02 +0000
Subject: Re: Problem with EXEC and PASSTHRU
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-243616@lists.php.net to get a copy of this message
Matt Beechey wrote:
I am writing a php website for users to edit a global whitelist for Spam Assassin - all is going fairly well considering I hadn't ever used php until a couple of days ago. My problem is I need to restart AMAVISD-NEW after the user saves the changes. I've acheived this using SUDO and giving the www-data users the rights to SUDO amavisd-new. My problem is simply a user friendlyness issue - below is the code I'm running - if(isset($_POST["SAVE"])) { file_put_contents("/etc/spamassassin/whitelist.cf", $_SESSION[whitelist]); $_SESSION[count]=0; echo "Restarting the service.........</A></P>"; exec('sudo /usr/sbin/amavisd-new reload'); echo "Service was restarted...... Returning to the main page."; sleep(4) echo '<meta http-equiv="refresh" content="0;URL=index.php">'; } The problem is that the Restarting the Service dialogue doesn't get displayed until AFTER the Service Restarts even though it appears before the shell_exec command. I've tried exec and passthru and its always the same - I want it to display the "Service was restarted" - wait for 4 seconds and then redirect to the main page. Instead nothing happens on screen for the browser user until the service has restarted at which point they are returned to index.php - its as if the exec and the sleep and the refresh to index.php are all kind of running concurently. Can someone PLEASE tell me what I'm doing wrong - or shed light on how I should do this. Thanks, Matt
-- You have to keep in mind that you are dealing with the difference in speed between something that is taking place on the sever and something that is being transmitted over a network. You don't make it clear whether this is an in-house site or whether it is used by people at a distance. If the latter, what you describe is not surprising at all. I've never had a reason to look into how PHP sequences events when it pumps out a web page, but it's not unusual for scripts in Perl, for instance, to show delays in browser output when doing something on the server. One consideration would be how long amavisd-new takes to reload. I'm not very well-informed about hacking and security, but it would seem to me that you are taking a risk by giving users root privileges to restart amavisd-new. _____________________ Myron Turner http://www.mturner.org/XML_PullParser/

« previous php.general (#243616) next »