Re: Problem with EXEC and PASSTHRU

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



# matt@xxxxxxxxxxxx / 2006-10-25 20:35:29 +1300:
> 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.

    You're forgetting that the server, the browser, and anything between
    may cache the data into chunks of any size.

    Even if the browser /did/ receive the data "in real time" your code
    would be wrong: you're ignoring the basic structure of a HTML
    document, and any browser worth that label should ignore the meta
    tag.

    Do this instead:

    // ...
    file_put_contents("/etc/spamassassin/whitelist.cf", $_SESSION[whitelist]);
    $_SESSION[count]=0;
    exec('sudo /usr/sbin/amavisd-new reload');
    ?>
    <html>
    <head>
    <meta http-equiv="refresh" content="4;URL=index.php">
    </head>
    <body>
    Service was restarted...... Returning to the main page.
    </body>
-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE.             http://bash.org/?255991

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux